| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Domain.Entities.Store.ValueObject;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Admin.Store.Product.Get;
- public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Result<Response>>
- {
- public async Task<Result<Response>> Handle(Query request, CancellationToken ct)
- {
- var product = await db.Product
- .AsNoTracking()
- .Include(c => c.Game)
- .Where(c => c.ID == request.ID)
- .Select(c => new Response(
- c.ID,
- c.GameID ?? 0,
- c.Game!.KorName,
- c.Name,
- c.Description,
- c.Thumbnail,
- c.Type,
- c.Price,
- c.DiscountType,
- c.DiscountValue,
- c.DiscountType == DiscountType.Percent
- ? (c.Price - (c.Price * c.DiscountValue / 100) < 0 ? 0 : c.Price - (c.Price * c.DiscountValue / 100))
- : c.DiscountType == DiscountType.Amount
- ? (c.Price - c.DiscountValue < 0 ? 0 : c.Price - c.DiscountValue)
- : c.Price,
- c.Stock,
- c.MinPurchase,
- c.MaxPurchase,
- c.IsActive,
- c.Order,
- c.SaleStartAt,
- c.SaleEndAt,
- c.CreatedAt,
- c.UpdatedAt,
- c.RequireDonationChannel
- ))
- .FirstOrDefaultAsync(ct);
- if (product is null)
- {
- return Result.Failure<Response>(Error.NotFound("Product.NotFound", "상품을 찾을 수 없습니다."));
- }
- return Result.Success(product);
- }
- }
|