Handler.cs 796 B

12345678910111213141516171819202122232425
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Domain.Entities.Donations.ValueObject;
  4. namespace Application.Features.Api.DonationRemote.IgnoreAlert;
  5. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
  6. {
  7. public async Task Handle(Command request, CancellationToken ct)
  8. {
  9. var alert = await db.DonationAlert.FindAsync([request.AlertID], ct);
  10. if (alert is null)
  11. {
  12. throw new KeyNotFoundException("알림을 찾을 수 없습니다.");
  13. }
  14. if (alert.Status == AlertStatus.Playing)
  15. {
  16. throw new InvalidOperationException("재생 중인 알림은 무시할 수 없습니다.");
  17. }
  18. alert.MarkIgnored();
  19. await db.SaveChangesAsync(ct);
  20. }
  21. }