-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchClientsHandler.cs
More file actions
29 lines (25 loc) · 1.2 KB
/
Copy pathFetchClientsHandler.cs
File metadata and controls
29 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
namespace HttpsRichardy.Federation.Application.Handlers.Client;
public sealed class FetchClientsHandler(IClientCollection clientCollection) :
IDispatchHandler<ClientsFetchParameters, Result<Pagination<ClientScheme>>>
{
public async Task<Result<Pagination<ClientScheme>>> HandleAsync(
ClientsFetchParameters parameters, CancellationToken cancellation = default)
{
var filters = ClientFilters.WithSpecifications()
.WithName(parameters.Name)
.WithClientId(parameters.ClientId)
.WithSort(parameters.Sort)
.WithPagination(parameters.Pagination)
.Build();
var clients = await clientCollection.GetClientsAsync(filters, cancellation);
var totalClients = await clientCollection.CountClientsAsync(filters, cancellation);
var pagination = new Pagination<ClientScheme>
{
Items = [.. clients.Select(client => ClientMapper.AsResponse(client))],
Total = (int)totalClients,
PageNumber = parameters.Pagination?.PageNumber ?? 1,
PageSize = parameters.Pagination?.PageSize ?? 20,
};
return Result<Pagination<ClientScheme>>.Success(pagination);
}
}