public ActionResult Subscribe([FromQuery] Models.Requests.SubscriptionProcessingRequest request)
        {
            var subscriptionProcessingRequest = new SubscriptionProcessingRequest(request.ChannelId, int.Parse(User.Id()));

            _subscriptionProcessingUseCase.Handle(subscriptionProcessingRequest, _subscriptionProcessingPresenter);
            return(_subscriptionProcessingPresenter.ContentResult);
        }
Beispiel #2
0
        public bool Handle(SubscriptionProcessingRequest request, IOutputPort <SubscriptionProcessingResponse> outputPort)
        {
            if (_userRepository.FindById(request.UserId) == null)
            {
                outputPort.Handle(new SubscriptionProcessingResponse(new[] { new Error(404, "user not found") }));
                return(false);
            }
            if (_channelRepository.FindById(request.ChannelId) == null)
            {
                outputPort.Handle(new SubscriptionProcessingResponse(new[] { new Error(404, "channel not found") }));
                return(false);
            }
            if (_channelRepository.FindByUserId(request.UserId) != null)
            {
                outputPort.Handle(new SubscriptionProcessingResponse(new[] { new Error(422, "you cannot subscribe to yourself") }));
                return(false);
            }
            int channelSubscriberId = _channelSubscriberRepository.HandleSubscription(request.UserId, request.ChannelId);

            outputPort.Handle(new SubscriptionProcessingResponse(channelSubscriberId));
            return(true);
        }