コード例 #1
0
        public async Task <ChannelSuggestionsResponse> Handle(ChannelSuggestionsRequest message)
        {
            var result = await _youTubeChannelDetailUseCase.Handle(
                new YouTubeChannelDetailRequest(
                    message.ChannelIds
                    )
                );

            var channels = result.IdentifiedChannels;

            var sourceFilterIsSpecified = !string.IsNullOrWhiteSpace(message.Source);

            if (sourceFilterIsSpecified)
            {
                channels = channels.Where(i => i.Source == message.Source).ToList();
            }

            var resultChannelIds = channels.Select(c => c.ChannelId).ToList();

            // fetch possible suggestions of these channel ids
            var userIdIsSpecified = !string.IsNullOrWhiteSpace(message.UserId);

            if (userIdIsSpecified)
            {
                var suggestions = await _suggestionRepository.GetAny(message.UserId, resultChannelIds);

                var suggestionChannelIds = suggestions.Select(s => s.Id.ChannelId).ToList();

                channels = channels
                           .Where(c => !suggestionChannelIds.Contains(c.ChannelId))
                           .ToList();
            }

            return(new ChannelSuggestionsResponse(channels));
        }
コード例 #2
0
        public async Task <IdentifySailingChannelResponse> Handle(IdentifySailingChannelRequest message)
        {
            // guard clause
            if (string.IsNullOrWhiteSpace(message.PossibleYouTubeChannelUrl))
            {
                return(new IdentifySailingChannelResponse(
                           ChannelIdentificationStatus.NotValid
                           ));
            }

            // try to identify a channel id from the URL
            var channelIdResponse = await _extractYouTubeChannelIdUseCase.Handle(
                new ExtractYouTubeChannelIdRequest(message.PossibleYouTubeChannelUrl)
                );

            // could not identity a channel
            if (string.IsNullOrWhiteSpace(channelIdResponse.ChannelId))
            {
                return(new IdentifySailingChannelResponse(
                           ChannelIdentificationStatus.NotValid
                           ));
            }

            // fetch details for youtube channel
            var channelDetails = await _youTubeChannelDetailUseCase.Handle(
                new YouTubeChannelDetailRequest(
                    new List <string>()
            {
                channelIdResponse.ChannelId
            }
                    )
                );

            if (channelDetails.IdentifiedChannels?.Count == 0)
            {
                return(new IdentifySailingChannelResponse(
                           ChannelIdentificationStatus.NotValid
                           ));
            }

            ChannelIdentificationDto channelDetail = channelDetails.IdentifiedChannels.First();

            // we discovered a newly listed channel
            if (channelDetail.Source.ToLower() == "yt")
            {
                // check if channel has been suggested before
                var suggestions = await _suggestionRepository.GetAny(
                    new List <string>() { channelIdResponse.ChannelId }
                    );

                // a suggestion does already exist for this channel
                if (suggestions.Count > 0)
                {
                    return(new IdentifySailingChannelResponse(
                               ChannelIdentificationStatus.AlreadySuggested
                               ));
                }

                // we found a novel channel at this point!
                return(new IdentifySailingChannelResponse(
                           ChannelIdentificationStatus.Novel,
                           channelDetail
                           ));
            }

            // this channel must already be listed
            return(new IdentifySailingChannelResponse(
                       ChannelIdentificationStatus.AlreadyListed,
                       channelDetail
                       ));
        }