feat: 实现租户列表查询接口
- 获取租户列表:GET /api/admin/v1/tenants - 用于填充租户下拉选择器 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using TakeoutSaaS.Domain.Tenants.Enums;
|
||||
using TakeoutSaaS.Shared.Abstractions.Serialization;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Tenants.Contracts;
|
||||
|
||||
/// <summary>
|
||||
/// 租户列表项 DTO(用于下拉选择器)。
|
||||
/// </summary>
|
||||
public sealed class TenantListItemDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 租户 ID(雪花,序列化为字符串)。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户编码。
|
||||
/// </summary>
|
||||
public string Code { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 租户名称。
|
||||
/// </summary>
|
||||
public string Name { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 租户简称。
|
||||
/// </summary>
|
||||
public string? ShortName { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户状态。
|
||||
/// </summary>
|
||||
public TenantStatus Status { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Tenants.Contracts;
|
||||
using TakeoutSaaS.Application.App.Tenants.Queries;
|
||||
using TakeoutSaaS.Domain.Tenants.Repositories;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Tenants.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 获取租户列表查询处理器。
|
||||
/// </summary>
|
||||
public sealed class ListTenantsQueryHandler(ITenantRepository tenantRepository)
|
||||
: IRequestHandler<ListTenantsQuery, IReadOnlyList<TenantListItemDto>>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<TenantListItemDto>> Handle(ListTenantsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 查询租户列表
|
||||
var tenants = await tenantRepository.GetAllAsync(request.Keyword, cancellationToken);
|
||||
|
||||
// 2. 映射 DTO
|
||||
return tenants.Select(t => new TenantListItemDto
|
||||
{
|
||||
Id = t.Id,
|
||||
Code = t.Code,
|
||||
Name = t.Name,
|
||||
ShortName = t.ShortName,
|
||||
Status = t.Status
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Tenants.Contracts;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Tenants.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 获取租户列表查询(用于下拉选择器)。
|
||||
/// </summary>
|
||||
public sealed record ListTenantsQuery : IRequest<IReadOnlyList<TenantListItemDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// 关键字(租户名称/编码)。
|
||||
/// </summary>
|
||||
public string? Keyword { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user