-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetOrdersQueryHandler.cs
29 lines (25 loc) · 1.09 KB
/
GetOrdersQueryHandler.cs
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 Ordering.Application.Orders.Queries.GetOrders
{
public class GetOrdersQueryHandler(IApplicationDbContext dbContext) : IQueryHandler<GetOrdersQuery, GetOrdersResult>
{
public async Task<GetOrdersResult> Handle(GetOrdersQuery query, CancellationToken cancellationToken)
{
// get orders
var pageIndex = query.PaginationRequest.PageIndex;
var pageSize = query.PaginationRequest.PageSize;
var totalCount = await dbContext.Orders.LongCountAsync(cancellationToken);
var orders = await dbContext.Orders
.Include(o => o.OrderItems)
.OrderBy(o => o.OrderName.Value)
.Skip(pageSize * pageIndex)
.Take(pageSize)
.ToListAsync(cancellationToken);
return new GetOrdersResult(
new PaginatedResult<OrderDto>(
pageIndex,
pageSize,
totalCount,
orders.ToOrderDtoList()));
}
}
}