feat: 增加分页排序与FluentValidation

This commit is contained in:
2025-12-02 10:50:43 +08:00
parent 93141fbf0c
commit 97bf6cacb0
63 changed files with 904 additions and 49 deletions

View File

@@ -23,7 +23,13 @@ public sealed class SearchDeliveryOrdersQueryHandler(
var tenantId = _tenantProvider.GetCurrentTenantId();
var orders = await _deliveryRepository.SearchAsync(tenantId, request.Status, request.OrderId, cancellationToken);
return orders.Select(order => new DeliveryOrderDto
var sorted = ApplySorting(orders, request.SortBy, request.SortDescending);
var paged = sorted
.Skip((request.Page - 1) * request.PageSize)
.Take(request.PageSize)
.ToList();
return paged.Select(order => new DeliveryOrderDto
{
Id = order.Id,
TenantId = order.TenantId,
@@ -37,7 +43,21 @@ public sealed class SearchDeliveryOrdersQueryHandler(
DispatchedAt = order.DispatchedAt,
PickedUpAt = order.PickedUpAt,
DeliveredAt = order.DeliveredAt,
FailureReason = order.FailureReason
FailureReason = order.FailureReason,
CreatedAt = order.CreatedAt
}).ToList();
}
private static IOrderedEnumerable<Domain.Deliveries.Entities.DeliveryOrder> ApplySorting(
IReadOnlyCollection<Domain.Deliveries.Entities.DeliveryOrder> orders,
string? sortBy,
bool sortDescending)
{
return sortBy?.ToLowerInvariant() switch
{
"status" => sortDescending ? orders.OrderByDescending(x => x.Status) : orders.OrderBy(x => x.Status),
"provider" => sortDescending ? orders.OrderByDescending(x => x.Provider) : orders.OrderBy(x => x.Provider),
_ => sortDescending ? orders.OrderByDescending(x => x.CreatedAt) : orders.OrderBy(x => x.CreatedAt)
};
}
}