Handler.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Domain.Entities.Donations.ValueObject;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Admin.Donation.Alert.Resend;
  6. public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
  7. {
  8. public async Task Handle(Command request, CancellationToken ct)
  9. {
  10. var alert = await db.DonationAlert.FirstOrDefaultAsync(x => x.ID == request.ID, ct)
  11. ?? throw new InvalidOperationException("후원 알림을 찾을 수 없습니다.");
  12. if (alert.Status == AlertStatus.Delivered)
  13. {
  14. throw new InvalidOperationException("이미 수신된 알림은 재전송할 수 없습니다.");
  15. }
  16. // Domain은 Failed/Skipped만 Resend() 허용 — 그 외 상태는 Queued로 재설정
  17. if (alert.Status is AlertStatus.Failed or AlertStatus.Skipped)
  18. {
  19. alert.Resend();
  20. }
  21. else
  22. {
  23. alert.MarkFailed();
  24. alert.Resend();
  25. }
  26. await db.SaveChangesAsync(ct);
  27. }
  28. }