fix(superadmin): add shops list to merchant detail view

- Add AdminShopSummaryDto to AdminDtos.cs
- Add Shops list to AdminMerchantDetailDto (optional, with default null)
- Fetch shops in GetMerchantDetailQueryHandler with status + category name joins
- Tab "Cửa hàng" now shows real shop data (name, category, status, created date)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-03-29 00:15:21 +07:00
parent e3893efa56
commit 1256ea0c00
2 changed files with 28 additions and 7 deletions

View File

@@ -78,7 +78,15 @@ public record AdminMerchantDetailDto(
DateTime CreatedAt,
DateTime? UpdatedAt,
DateTime? VerifiedAt,
Guid? VerifiedBy);
Guid? VerifiedBy,
List<AdminShopSummaryDto>? Shops = null);
/// <summary>
/// EN: Shop summary for merchant detail view.
/// VI: Tóm tắt cửa hàng cho trang chi tiết merchant.
/// </summary>
public record AdminShopSummaryDto(
Guid Id, string Name, string? Category, string? Status, DateTime CreatedAt);
#endregion

View File

@@ -4,6 +4,7 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using MerchantService.Domain.AggregatesModel.MerchantAggregate;
using MerchantService.Domain.AggregatesModel.ShopAggregate;
using MerchantService.Domain.Exceptions;
using MerchantService.Infrastructure;
@@ -54,10 +55,21 @@ public class GetMerchantDetailQueryHandler : IRequestHandler<GetMerchantDetailQu
.FirstOrDefaultAsync(cancellationToken)
?? throw new DomainException($"Merchant {request.MerchantId} not found");
var shopsCount = await _context.Shops
// EN: Fetch shops for this merchant with status names
// VI: Lấy danh sách shops của merchant với tên status
var shops = await _context.Shops
.AsNoTracking()
.Where(s => EF.Property<Guid>(s, "_merchantId") == request.MerchantId
&& !EF.Property<bool>(s, "_isDeleted"))
.CountAsync(cancellationToken);
.Join(_context.Set<ShopStatus>(), s => s.StatusId, st => st.Id, (s, st) => new { s, StatusName = st.Name })
.Join(_context.Set<BusinessCategory>(), x => x.s.CategoryId, c => c.Id, (x, c) => new { x.s, x.StatusName, CategoryName = c.Name })
.Select(x => new AdminShopSummaryDto(
x.s.Id,
EF.Property<string>(x.s, "_name"),
x.CategoryName,
x.StatusName,
EF.Property<DateTime>(x.s, "_createdAt")))
.ToListAsync(cancellationToken);
var staffCount = await _context.MerchantStaff
.CountAsync(s => s.MerchantId == request.MerchantId, cancellationToken);
@@ -69,15 +81,16 @@ public class GetMerchantDetailQueryHandler : IRequestHandler<GetMerchantDetailQu
raw.TypeName,
raw.StatusName,
raw.VerifName,
null, // BusinessInfo — owned type not easily joined, skip for now
null, // SettlementConfig — same
shopsCount,
null, // BusinessInfo
null, // SettlementConfig
shops.Count,
staffCount,
raw.PlanId,
PlanNames.ElementAtOrDefault(raw.PlanId) ?? "Starter",
raw.CreatedAt,
raw.UpdatedAt,
raw.VerifiedAt,
raw.VerifiedBy);
raw.VerifiedBy,
shops);
}
}