feat: 商户模块移除租户上下文依赖

This commit is contained in:
2026-01-29 13:52:36 +00:00
parent bb3bb842bc
commit 4dc5b067eb
31 changed files with 218 additions and 268 deletions

View File

@@ -2,7 +2,6 @@ using MediatR;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Application.App.Merchants.Commands;
using TakeoutSaaS.Domain.Merchants.Repositories;
using TakeoutSaaS.Shared.Abstractions.Tenancy;
namespace TakeoutSaaS.Application.App.Merchants.Handlers;
@@ -11,23 +10,21 @@ namespace TakeoutSaaS.Application.App.Merchants.Handlers;
/// </summary>
public sealed class DeleteMerchantCommandHandler(
IMerchantRepository merchantRepository,
ITenantProvider tenantProvider,
ILogger<DeleteMerchantCommandHandler> logger)
: IRequestHandler<DeleteMerchantCommand, bool>
{
/// <inheritdoc />
public async Task<bool> Handle(DeleteMerchantCommand request, CancellationToken cancellationToken)
{
// 1. 校验存在性
var tenantId = tenantProvider.GetCurrentTenantId();
var existing = await merchantRepository.FindByIdAsync(request.MerchantId, tenantId, cancellationToken);
// 1. 校验存在性(跨租户)
var existing = await merchantRepository.FindByIdAsync(request.MerchantId, cancellationToken);
if (existing == null)
{
return false;
}
// 2. 删除
await merchantRepository.DeleteMerchantAsync(request.MerchantId, tenantId, cancellationToken);
// 2. (空行后) 删除
await merchantRepository.DeleteMerchantAsync(request.MerchantId, existing.TenantId, cancellationToken);
await merchantRepository.SaveChangesAsync(cancellationToken);
logger.LogInformation("删除商户 {MerchantId}", request.MerchantId);