RemoteSkip.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Application.Abstractions.Hub;
  2. using Infrastructure.Hubs;
  3. using Web.Api.Common;
  4. using MediatR;
  5. using Microsoft.AspNetCore.SignalR;
  6. namespace Web.Api.Endpoints.Donation;
  7. /// <summary>리모콘 — 건너뛰기 (현재 재생 중 알림 즉시 종료 + 위젯/리모콘 broadcast)</summary>
  8. internal sealed class RemoteSkip : IEndpoint
  9. {
  10. public void MapEndpoint(IEndpointRouteBuilder app)
  11. {
  12. app.MapPost("api/donation/remote/skip/{widgetToken}", async (
  13. string widgetToken,
  14. ISender sender,
  15. IHubContext<DonationHub, IDonationHubClient> donationHub,
  16. CancellationToken ct
  17. ) => {
  18. var result = await sender.Send(new Application.Features.Api.DonationRemote.SkipCurrent.Command(widgetToken), ct);
  19. if (result.IsFailure)
  20. {
  21. return CustomResults.Problem(result);
  22. }
  23. // 위젯: 현재 알림 즉시 unmount + 다음 알림 진입. 리모콘: 행 상태를 skipped 로 갱신.
  24. await donationHub.Clients.Group(widgetToken).ReceiveSkip();
  25. if (result.Value.SkippedAlertID is int skippedID)
  26. {
  27. await donationHub.Clients.Group(widgetToken).ReceiveAlertStatusUpdate(new
  28. {
  29. alertID = skippedID,
  30. status = "skipped"
  31. });
  32. }
  33. return ApiResponse.Ok();
  34. })
  35. .WithTags("DonationRemote")
  36. .RequireAuthorization();
  37. }
  38. }