From e483d325ae1cef21450e81324463c146d8bfbf5e Mon Sep 17 00:00:00 2001 From: Zaprit Date: Mon, 20 Feb 2023 04:37:37 +0000 Subject: [PATCH] User Search API (#680) * Added User Search API * Applied limit to user search * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh * 1 line fix, woo! --------- Co-authored-by: Josh --- .../Controllers/UserEndpoints.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs b/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs index a317b9d8..e1505241 100644 --- a/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs +++ b/ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs @@ -50,6 +50,29 @@ public class UserEndpoints : ApiEndpointController return this.Ok(user); } + /// + /// Searches for the user based on the query + /// + /// The search query + /// A list of users + /// The list of users, if any were found + /// No users matched the query + [HttpGet("search/user")] + [ProducesResponseType(typeof(User), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task SearchUsers(string query) + { + List users = await this.database.Users + .Where(u => u.PermissionLevel != PermissionLevel.Banned && u.Username.Contains(query)) + .Where(u => u.ProfileVisibility == PrivacyType.All) // TODO: change check for when user is logged in + .OrderByDescending(b => b.UserId) + .Take(20) + .ToListAsync(); + if (!users.Any()) return this.NotFound(); + + return this.Ok(users); + } + /// /// Gets a user and their information from the database. ///