mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-21 08:42:27 +00:00
User Search API (#680)
* Added User Search API * Applied limit to user search * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh <josh@slendy.pw> * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh <josh@slendy.pw> * Update ProjectLighthouse.Servers.API/Controllers/UserEndpoints.cs Co-authored-by: Josh <josh@slendy.pw> * 1 line fix, woo! --------- Co-authored-by: Josh <josh@slendy.pw>
This commit is contained in:
parent
8030301739
commit
e483d325ae
1 changed files with 23 additions and 0 deletions
|
@ -50,6 +50,29 @@ public class UserEndpoints : ApiEndpointController
|
||||||
return this.Ok(user);
|
return this.Ok(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches for the user based on the query
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The search query</param>
|
||||||
|
/// <returns>A list of users</returns>
|
||||||
|
/// <response code="200">The list of users, if any were found</response>
|
||||||
|
/// <response code="404">No users matched the query</response>
|
||||||
|
[HttpGet("search/user")]
|
||||||
|
[ProducesResponseType(typeof(User), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<IActionResult> SearchUsers(string query)
|
||||||
|
{
|
||||||
|
List<User> 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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a user and their information from the database.
|
/// Gets a user and their information from the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue