diff --git a/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs b/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs index cb095a60..d5e074b7 100644 --- a/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs +++ b/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs @@ -96,8 +96,7 @@ public class UserEndpoints : ApiEndpointController [HttpPost("user/inviteToken/{username}")] public async Task CreateUserInviteToken([FromRoute] string? username) { - if (!Configuration.ServerConfiguration.Instance.Authentication.RegistrationEnabled) - return this.NotFound(); + if (!Configuration.ServerConfiguration.Instance.Authentication.RegistrationEnabled) return this.NotFound(); string? authHeader = this.Request.Headers["Authorization"]; if (string.IsNullOrWhiteSpace(authHeader)) return this.NotFound(); @@ -125,4 +124,29 @@ public class UserEndpoints : ApiEndpointController return this.Ok(token.Token); } + + /// + /// Gets a list of online users and returns it. + /// + /// Page number. Increments skip value by clamp value + /// Number of entries to clamp response to + /// Array of online users ordered by login time + /// List of users + [HttpGet("users/online")] + [ProducesResponseType(typeof(ApiUser), StatusCodes.Status200OK)] + public async Task GetOnlineUsers(int page = 0, int clamp = 50) + { + if (clamp > 100) return this.BadRequest(); + + List onlineUsers = (await this.database.Users + .Where(u => u.PermissionLevel != PermissionLevel.Banned) + .Where(u => u.ProfileVisibility == PrivacyType.All) + .Where(u => u.GetStatus(this.database).StatusType == StatusType.Online) + .OrderByDescending(u => u.LastLogin) + .Skip(page * clamp) + .Take(clamp) + .ToListAsync()).ToSerializableList(ApiUser.CreateFromEntity); + + return this.Ok(onlineUsers); + } } \ No newline at end of file