[backend/api] Add endpoint to search user by username and host
This commit is contained in:
parent
da2cb76aab
commit
03def5b290
1 changed files with 20 additions and 0 deletions
|
@ -137,4 +137,24 @@ public class SearchController(
|
|||
|
||||
throw GracefulException.BadRequest("Invalid lookup target");
|
||||
}
|
||||
|
||||
[HttpGet("acct")]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task<IEnumerable<UserResponse>> SearchUserByMention(
|
||||
[FromQuery] string? username, [FromQuery] string? host
|
||||
)
|
||||
{
|
||||
var user = HttpContext.GetUser();
|
||||
|
||||
var users = await db.Users
|
||||
.IncludeCommonProperties()
|
||||
.Where(p => p != user
|
||||
&& (username == null || p.UsernameLower.StartsWith(username.ToLower()))
|
||||
&& (host == null || p.Host != null && p.Host.StartsWith(host.ToLower())))
|
||||
.OrderByDescending(p => p.NotesCount)
|
||||
.Take(10)
|
||||
.ToListAsync();
|
||||
|
||||
return await userRenderer.RenderManyAsync(users);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue