Handler.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Domain.Entities.Common.ValueObject;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Admin.Mail.Resend;
  6. public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
  7. {
  8. public async Task Handle(Command request, CancellationToken ct)
  9. {
  10. if (request.IDs is null || request.IDs.Length == 0)
  11. {
  12. return;
  13. }
  14. var now = DateTime.UtcNow;
  15. // Status를 Pending 으로 되돌리고, RetryCount 리셋, NextRetryAt 즉시 처리되도록 설정
  16. await db.EmailLog
  17. .Where(x => request.IDs.Contains(x.ID))
  18. .ExecuteUpdateAsync(s => s
  19. .SetProperty(x => x.Status, MailStatus.Pending)
  20. .SetProperty(x => x.RetryCount, 0)
  21. .SetProperty(x => x.NextRetryAt, now)
  22. .SetProperty(x => x.LastError, (string?)null)
  23. .SetProperty(x => x.ProcessedAt, (DateTime?)null)
  24. .SetProperty(x => x.FailedAt, (DateTime?)null), ct);
  25. }
  26. }