Handler.cs 769 B

123456789101112131415161718192021222324
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.EntityFrameworkCore;
  4. using SharedKernel.Results;
  5. namespace Application.Features.Admin.Store.GameCatalog.Delete;
  6. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
  7. {
  8. public async Task<Result> Handle(Command request, CancellationToken ct)
  9. {
  10. var row = await db.GameProductCatalog.FirstOrDefaultAsync(c => c.ID == request.ID, ct);
  11. if (row is null)
  12. {
  13. return Result.Failure(Error.NotFound("GameCatalog.NotFound", "카탈로그 항목을 찾을 수 없습니다."));
  14. }
  15. db.GameProductCatalog.Remove(row);
  16. await db.SaveChangesAsync(ct);
  17. return Result.Success();
  18. }
  19. }