Handler.cs 897 B

123456789101112131415161718192021222324252627
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using SharedKernel.Results;
  4. using Domain.Entities.Donations.ValueObject;
  5. using Microsoft.EntityFrameworkCore;
  6. namespace Application.Features.Api.Crew.EndSession;
  7. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
  8. {
  9. public async Task<Result> Handle(Command request, CancellationToken ct)
  10. {
  11. var session = await db.CrewSession
  12. .FirstOrDefaultAsync(s => s.ID == request.CrewSessionID && s.Status == CrewSessionStatus.Active, ct);
  13. if (session is null)
  14. {
  15. return Result.Failure(Error.NotFound("Crew.ActiveSessionNotFound", "활성 세션을 찾을 수 없습니다."));
  16. }
  17. session.End();
  18. await db.SaveChangesAsync(ct);
  19. // 쪽지 발송은 Endpoint에서 처리
  20. return Result.Success();
  21. }
  22. }