/// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // TOPICS OVERVIEW
            graphQlQuery.FieldAsync <ListGraphType <SubscriberType> >(
                "subscriberHistory",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelId"
            },
                    new QueryArgument <IntGraphType> {
                Name = "days"
            }
                    ),
                resolve: async(context) =>
            {
                var result = await _subscriberRepository.GetHistory(
                    context.GetArgument <string>("channelId"),
                    context.GetArgument <int>("days", 7)
                    );

                // map entity to model
                return(_mapper.Map <List <SubscriberModel> >(result));
            }
                );
        }
示例#2
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // LANGUAGES: a list of all lang codes
            graphQlQuery.FieldAsync <BooleanGraphType>(
                "flagExists",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelId"
            }
                    ),
                resolve: async(context) =>
            {
                // read user context dictionary
                var userContext = (GraphQlUserContext)context.UserContext;
                var userId      = userContext.GetUserId();

                // require user to be authenticated
                if (userId == null)
                {
                    return(false);
                }

                // map entity to model
                return(await _flagRepository.FlagExists(
                           context.GetArgument <string>("channelId"),
                           userId
                           ));
            }
                );
        }
示例#3
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // LANGUAGES: a list of all lang codes
            graphQlQuery.FieldAsync <SearchResultType>(
                "searchResults",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "query"
            }
                    ),
                resolve: async(context) =>
            {
                var searchResult = await _searchUseCase.Handle(new SearchRequest(
                                                                   context.GetArgument <string>("query")
                                                                   ));

                var channelsWithTruncatedDescription =
                    TruncateChannelDescriptions(searchResult.Channels);

                var truncatedDescriptionResults = searchResult with {
                    Channels = channelsWithTruncatedDescription
                };

                // map entity to model
                return(_mapper.Map <SearchResultModel>(truncatedDescriptionResults));
            }
                );
        }
示例#4
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // TOPICS OVERVIEW
            graphQlQuery.FieldAsync <ListGraphType <TopicOverviewType> >(
                "topicsOverview",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "language"
            }
                    ),
                resolve: async(context) =>
            {
                var result = await _topicsOverviewUseCase.Handle(
                    new TopicsOverviewRequest(context.GetArgument <string>("language"))
                    );

                // map entity to model
                return(_mapper.Map <List <TopicOverviewModel> >(result.Topics));
            }
                );

            // LANGUAGES: a list of all lang codes
            graphQlQuery.FieldAsync <TopicDetailType>(
                "topicDetail",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "topicId"
            }
                    ),
                resolve: async(context) =>
            {
                var result = await _topicDetailUseCase.Handle(
                    new TopicDetailRequest(context.GetArgument <string>("topicId"))
                    );

                var truncatedDescriptionResult = result with {
                    Channels = TruncateChannelDescriptions(result.Channels)
                };

                // map entity to model
                return(_mapper.Map <TopicDetailModel>(truncatedDescriptionResult));
            }
                );
        }
示例#5
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // LANGUAGES: a list of all lang codes
            graphQlQuery.FieldAsync <ListGraphType <LanguageType> >(
                "languages",
                resolve: async(context) =>
            {
                var languages = await _languageRepository.GetAll();

                // map entity to model
                return(_mapper.Map <List <LanguageModel> >(languages));
            }
                );
        }
示例#6
0
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // IDENTIFY CHANNELS: take a list of url hints and identify sailing channels from them
            graphQlQuery.FieldAsync <ListGraphType <ChannelIdentificationType> >(
                "channelSuggestions",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ListGraphType <StringGraphType> > > {
                Name = "channelIds"
            },
                    new QueryArgument <StringGraphType> {
                Name = "source"
            }
                    ),
                resolve: async(context) =>
            {
                // read user context dictionary
                var userContext = (GraphQlUserContext)context.UserContext;
                var userId      = userContext.GetUserId();

                // require user to be authenticated
                if (userId == null)
                {
                    return(null);
                }

                var result = await _channelSuggestionsUseCase.Handle(
                    new ChannelSuggestionsRequest(
                        context.GetArgument <List <string> >("channelIds"),
                        userId,
                        context.GetArgument <string>("source")
                        )
                    );

                var truncatedSuggestions =
                    TruncateChannelIdentificationDescription(result.Suggestions);

                // map entity to model
                return(_mapper.Map <List <ChannelIdentificationModel> >(truncatedSuggestions));
            }
                );
        }
示例#7
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // LATEST VIDEO: returns the latest video of a channel
            graphQlQuery.FieldAsync <VideoType>(
                "latestVideo",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "channelId"
            }
                    ),
                resolve: async(context) =>
            {
                var channelId = context.GetArgument <string>("channelId");

                var video   = await _videoRepository.GetLatest(channelId);
                var channel = await _channelRepository.Get(channelId);

                var enrichedVideo = video with {
                    Channel = channel
                };

                // map entity to model
                return(_mapper.Map <VideoModel>(enrichedVideo));
            }
                );

            // VIDEOS: returns all videos of a certain channel
            graphQlQuery.FieldAsync <ListGraphType <VideoType> >(
                "videos",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "channelId"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "skip"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "take"
            }
                    ),
                resolve: async(context) =>
            {
                var channelId = context.GetArgument <string>("channelId");
                var channel   = await _channelRepository.Get(channelId);

                var videos = await _videoRepository.GetByChannel(
                    channelId,
                    context.GetArgument <int>("skip"),
                    context.GetArgument <int>("take")
                    );

                var enrichedVideos = EnrichVideosWithChannel(videos, channel);

                // map entity to model
                return(_mapper.Map <List <VideoModel> >(enrichedVideos));
            }
                );

            // VIDEOS: returns all videos of a certain channel
            graphQlQuery.FieldAsync <IntGraphType>(
                "videoCount",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "channelId"
            }
                    ),
                resolve: async(context) =>
            {
                var videoCount = await _videoRepository.CountByChannel(
                    context.GetArgument <string>("channelId")
                    );

                // map entity to model
                return(videoCount);
            }
                );

            // VIDEO COUNT TOTAL
            graphQlQuery.FieldAsync <IntGraphType>(
                "videoCountTotal",
                resolve: async(context) =>
            {
                var videoCount = await _videoRepository.Count();

                // map entity to model
                return(videoCount);
            }
                );

            // VIDEO PUBLISH DISTRIBUTION
            graphQlQuery.FieldAsync <ListGraphType <VideoPublishAggregationItemType> >(
                "videoPublishDistribution",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "channelId"
            }
                    ),
                resolve: async(context) =>
            {
                try
                {
                    var result = await _aggregateVideoPublishTimesUseCase.Handle(
                        new AggregateVideoPublishTimesRequest(
                            context.GetArgument <string>("channelId")
                            )
                        );

                    var aggregationModels = new List <VideoPublishAggregationItemModel>();

                    foreach (var daysOfWeek in result.Aggregation)
                    {
                        foreach (var hourOfDay in daysOfWeek.Value)
                        {
                            aggregationModels.Add(new VideoPublishAggregationItemModel()
                            {
                                DayOfTheWeek    = (int)daysOfWeek.Key,
                                HourOfTheDay    = hourOfDay.Key,
                                PublishedVideos = hourOfDay.Value
                            });
                        }
                    }

                    // map entity to model
                    return(aggregationModels);
                }
                catch
                {
                    return(null);
                }
            }
                );
        }
示例#8
0
        /// <summary>
        /// Resolves all queries on guest accesses
        /// </summary>
        /// <param name="graphQlQuery"></param>
        public void ResolveQuery(GraphQlQuery graphQlQuery)
        {
            // GUEST ACCESSES: list of all guest access entries
            graphQlQuery.FieldAsync <ListGraphType <ChannelType> >(
                "channels",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "sortBy"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "skip"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "take"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "language"
            }
                    ),
                resolve: async context =>
            {
                var channels = await _channelRepository.GetAll(
                    (ChannelSorting)Enum.Parse(typeof(ChannelSorting), context.GetArgument <string>("sortBy")),
                    context.GetArgument <int>("skip"),
                    context.GetArgument <int>("take"),
                    context.GetArgument <string>("language")
                    );

                var channelsWithTruncatedDescription =
                    TruncateChannelDescriptions(channels);

                // map entity to model
                return(_mapper.Map <List <ChannelModel> >(channelsWithTruncatedDescription));
            }
                );

            // CHANNEL: retrieve single channel
            graphQlQuery.FieldAsync <ChannelType>(
                "channel",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                var channel = await _channelRepository.Get(context.GetArgument <string>("id"));

                // map entity to model
                return(_mapper.Map <ChannelModel>(channel));
            }
                );

            // CHANNEL COUNT TOTAL
            graphQlQuery.FieldAsync <IntGraphType>(
                "channelCountTotal",
                resolve: async(context) =>
            {
                var channelCount = await _channelRepository.Count();

                // map entity to model
                return(channelCount);
            }
                );

            // IDENTIFY CHANNELS: take a list of url hints and identify sailing channels from them
            graphQlQuery.FieldAsync <ChannelIdentificationType>(
                "identifyChannel",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelUrlHint"
            }
                    ),
                resolve: async context =>
            {
                var result = await _identifySailingChannelUseCase.Handle(
                    new IdentifySailingChannelRequest(
                        context.GetArgument <string>("channelUrlHint")
                        )
                    );

                var identifiedChannel = result.IdentifiedChannel;

                // truncate description
                if (result.IdentifiedChannel != null && result.IdentifiedChannel.Channel != null)
                {
                    identifiedChannel = identifiedChannel with {
                        Channel = identifiedChannel.Channel with {
                            Description = identifiedChannel.Channel.Description.Truncate(300, true)
                        }
                    };
                }

                // map entity to model
                return(_mapper.Map <ChannelIdentificationModel>(identifiedChannel));
            }
                );

            // CHANNEL PUBLISH PREDICTION
            graphQlQuery.FieldAsync <ListGraphType <PublishSchedulePredictionType> >(
                "channelPublishPrediction",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "channelId"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "filterBelowAverage", DefaultValue = false
            }
                    ),
                resolve: async(context) =>
            {
                var channelId          = context.GetArgument <string>("channelId");
                var filterBelowAverage = context.GetArgument <bool>("filterBelowAverage");

                var predictionResult = await _channelPublishPredictionRepository.Get(channelId);

                if (predictionResult is null or {
                    Gradient: <= 0.7f
                })
                {
                    return(null);
                }

                var predictionItems = predictionResult.PredictionItems;

                if (filterBelowAverage)
                {
                    predictionItems = predictionItems.Where(i => i.DeviationFromAverage > 0);
                }

                return(_mapper.Map <List <PublishSchedulePredictionModel> >(predictionItems));
            });