Handler.cs 805 B

12345678910111213141516171819202122232425
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using SharedKernel.Results;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Api.Crew.DeleteWidgetConfig;
  6. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
  7. {
  8. public async Task<Result> Handle(Command request, CancellationToken ct)
  9. {
  10. var config = await db.CrewWidgetConfig
  11. .FirstOrDefaultAsync(c => c.ID == request.ID && c.ChannelID == request.ChannelID, ct);
  12. if (config is null)
  13. {
  14. return Result.Failure(Error.NotFound("CrewWidget.NotFound", "설정을 찾을 수 없습니다."));
  15. }
  16. db.CrewWidgetConfig.Remove(config);
  17. await db.SaveChangesAsync(ct);
  18. return Result.Success();
  19. }
  20. }