Add get user by username api endpoint

This commit is contained in:
Slendy 2022-10-04 00:02:33 -05:00
parent 5bc875bc04
commit 355ec45b20
No known key found for this signature in database
GPG key ID: 7288D68361B91428

View file

@ -39,6 +39,17 @@ public class UserEndpoints : ApiEndpointController
return this.Ok(user);
}
[HttpGet("username/{username}")]
[ProducesResponseType(typeof(User), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetUser(string username)
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (user == null) return this.NotFound();
return this.Ok(user);
}
/// <summary>
/// Gets a user and their information from the database.
/// </summary>