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.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Domain.Stores.Repositories;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Abstractions.Tenancy;
namespace TakeoutSaaS.Application.App.Stores.Handlers;
@@ -12,13 +13,13 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
public sealed class SearchStoresQueryHandler(
IStoreRepository storeRepository,
ITenantProvider tenantProvider)
: IRequestHandler<SearchStoresQuery, IReadOnlyList<StoreDto>>
: IRequestHandler<SearchStoresQuery, PagedResult<StoreDto>>
{
private readonly IStoreRepository _storeRepository = storeRepository;
private readonly ITenantProvider _tenantProvider = tenantProvider;
/// <inheritdoc />
public async Task<IReadOnlyList<StoreDto>> Handle(SearchStoresQuery request, CancellationToken cancellationToken)
public async Task<PagedResult<StoreDto>> Handle(SearchStoresQuery request, CancellationToken cancellationToken)
{
var tenantId = _tenantProvider.GetCurrentTenantId();
var stores = await _storeRepository.SearchAsync(tenantId, request.Status, cancellationToken);
@@ -34,7 +35,8 @@ public sealed class SearchStoresQueryHandler(
.Take(request.PageSize)
.ToList();
return paged.Select(MapToDto).ToList();
var items = paged.Select(MapToDto).ToList();
return new PagedResult<StoreDto>(items, request.Page, request.PageSize, stores.Count);
}
private static IOrderedEnumerable<Domain.Stores.Entities.Store> ApplySorting(

View File

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