-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchUsersHandler.cs
More file actions
24 lines (20 loc) · 984 Bytes
/
Copy pathFetchUsersHandler.cs
File metadata and controls
24 lines (20 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
namespace Vinder.Federation.Application.Handlers.User;
public sealed class FetchUsersHandler(IUserCollection collection) :
IMessageHandler<UsersFetchParameters, Result<Pagination<UserDetailsScheme>>>
{
public async Task<Result<Pagination<UserDetailsScheme>>> HandleAsync(
UsersFetchParameters parameters, CancellationToken cancellation = default)
{
var filters = UserMapper.AsFilters(parameters);
var users = await collection.GetUsersAsync(filters, cancellation);
var totalUsers = await collection.CountAsync(filters, cancellation);
var pagination = new Pagination<UserDetailsScheme>
{
Items = [.. users.Select(user => UserMapper.AsResponse(user))],
Total = (int) totalUsers,
PageNumber = parameters.Pagination?.PageNumber ?? 1,
PageSize = parameters.Pagination?.PageSize ?? 20,
};
return Result<Pagination<UserDetailsScheme>>.Success(pagination);
}
}