| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Application.Abstractions.Crypto;
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Admin.Store.Shipment.Get;
- public sealed class Handler(IAppDbContext db, IFieldEncryptor encryptor) : IQueryHandler<Query, Result<Response>>
- {
- public async Task<Result<Response>> Handle(Query request, CancellationToken ct)
- {
- var shipment = await db.Shipment
- .AsNoTracking()
- .Include(s => s.Order).ThenInclude(o => o!.Member)
- .Where(s => s.ID == request.ID)
- .FirstOrDefaultAsync(ct);
- if (shipment is null)
- {
- return Result.Failure<Response>(Error.NotFound("Shipment.NotFound", "배송 정보를 찾을 수 없습니다."));
- }
- string? recipientName = null;
- string? phone = null;
- string? zipCode = null;
- string? address1 = null;
- string? address2 = null;
- if (request.WithAddress)
- {
- recipientName = encryptor.Decrypt(shipment.RecipientName_Encrypted, shipment.KeyVersion);
- phone = encryptor.Decrypt(shipment.Phone_Encrypted, shipment.KeyVersion);
- zipCode = shipment.ZipCode;
- address1 = encryptor.Decrypt(shipment.Address1_Encrypted, shipment.KeyVersion);
- address2 = encryptor.Decrypt(shipment.Address2_Encrypted, shipment.KeyVersion);
- }
- return Result.Success(new Response(
- ID: shipment.ID,
- OrderID: shipment.OrderID,
- OrderNumber: shipment.Order?.OrderNumber ?? "-",
- BuyerMemberID: shipment.Order?.MemberID ?? 0,
- BuyerEmail: shipment.Order?.Member?.Email ?? "-",
- Status: shipment.Status,
- Carrier: shipment.Carrier,
- TrackingNumber: shipment.TrackingNumber,
- ShippingFee: shipment.ShippingFee,
- AdminMemo: shipment.AdminMemo,
- CreatedAt: shipment.CreatedAt,
- ShippedAt: shipment.ShippedAt,
- DeliveredAt: shipment.DeliveredAt,
- RecipientName: recipientName,
- Phone: phone,
- ZipCode: zipCode,
- Address1: address1,
- Address2: address2
- ));
- }
- }
|