feat: 列表接口分页排序与验证

This commit is contained in:
2025-12-02 11:13:14 +08:00
parent 92e4f8caa4
commit e8777faf71
19 changed files with 110 additions and 41 deletions

View File

@@ -2,6 +2,7 @@ using MediatR;
using TakeoutSaaS.Application.App.Products.Dto;
using TakeoutSaaS.Application.App.Products.Queries;
using TakeoutSaaS.Domain.Products.Repositories;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Abstractions.Tenancy;
namespace TakeoutSaaS.Application.App.Products.Handlers;
@@ -12,13 +13,13 @@ namespace TakeoutSaaS.Application.App.Products.Handlers;
public sealed class SearchProductsQueryHandler(
IProductRepository productRepository,
ITenantProvider tenantProvider)
: IRequestHandler<SearchProductsQuery, IReadOnlyList<ProductDto>>
: IRequestHandler<SearchProductsQuery, PagedResult<ProductDto>>
{
private readonly IProductRepository _productRepository = productRepository;
private readonly ITenantProvider _tenantProvider = tenantProvider;
/// <inheritdoc />
public async Task<IReadOnlyList<ProductDto>> Handle(SearchProductsQuery request, CancellationToken cancellationToken)
public async Task<PagedResult<ProductDto>> Handle(SearchProductsQuery request, CancellationToken cancellationToken)
{
var tenantId = _tenantProvider.GetCurrentTenantId();
var products = await _productRepository.SearchAsync(tenantId, request.CategoryId, request.Status, cancellationToken);
@@ -34,7 +35,8 @@ public sealed class SearchProductsQueryHandler(
.Take(request.PageSize)
.ToList();
return paged.Select(MapToDto).ToList();
var items = paged.Select(MapToDto).ToList();
return new PagedResult<ProductDto>(items, request.Page, request.PageSize, products.Count);
}
private static IOrderedEnumerable<Domain.Products.Entities.Product> ApplySorting(

View File

@@ -1,13 +1,14 @@
using MediatR;
using TakeoutSaaS.Application.App.Products.Dto;
using TakeoutSaaS.Domain.Products.Enums;
using TakeoutSaaS.Shared.Abstractions.Results;
namespace TakeoutSaaS.Application.App.Products.Queries;
/// <summary>
/// 商品列表查询。
/// </summary>
public sealed class SearchProductsQuery : IRequest<IReadOnlyList<ProductDto>>
public sealed class SearchProductsQuery : IRequest<PagedResult<ProductDto>>
{
/// <summary>
/// 门店 ID可选