| 123456789101112131415161718192021222324252627282930313233 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Domain.Entities.Donations.ValueObject;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Admin.Donation.Alert.Resend;
- public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
- {
- public async Task Handle(Command request, CancellationToken ct)
- {
- var alert = await db.DonationAlert.FirstOrDefaultAsync(x => x.ID == request.ID, ct)
- ?? throw new InvalidOperationException("후원 알림을 찾을 수 없습니다.");
- if (alert.Status == AlertStatus.Delivered)
- {
- throw new InvalidOperationException("이미 수신된 알림은 재전송할 수 없습니다.");
- }
- // Domain은 Failed/Skipped만 Resend() 허용 — 그 외 상태는 Queued로 재설정
- if (alert.Status is AlertStatus.Failed or AlertStatus.Skipped)
- {
- alert.Resend();
- }
- else
- {
- alert.MarkFailed();
- alert.Resend();
- }
- await db.SaveChangesAsync(ct);
- }
- }
|