Handler.cs 877 B

123456789101112131415161718192021222324
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.YouTube;
  3. using SharedKernel.Results;
  4. namespace Application.Features.Admin.Channel.YouTubePubSub.Resubscribe;
  5. internal sealed class Handler(IYouTubePubSubService pubSubService) : ICommandHandler<Command, Result>
  6. {
  7. public async Task<Result> Handle(Command request, CancellationToken ct)
  8. {
  9. if (string.IsNullOrWhiteSpace(request.YouTubeChannelID))
  10. {
  11. return Result.Failure(Error.Problem("YouTubePubSub.ChannelIDRequired", "YouTube Channel ID가 필요합니다."));
  12. }
  13. var success = await pubSubService.SubscribeAsync(request.YouTubeChannelID, ct);
  14. if (!success)
  15. {
  16. return Result.Failure(Error.Problem("YouTubePubSub.SubscribeFailed", "구독 요청이 실패했습니다."));
  17. }
  18. return Result.Success();
  19. }
  20. }