コード例 #1
0
        public ContentCollectionType(ContentCollection contentCollection, Func <IContentStore> getContentStore, string[] languages, string defaultLanguage)
        {
            if (NameConverter.TryConvertToGraphQLName(contentCollection.Name, out string graphQLName))
            {
                Name        = graphQLName;
                Description = "A collection that contains content of a specific type.";

                Field(cc => cc.Id).Description("The id of the content collection.");
                Field(cc => cc.Name).Description("The name of the content collection.");
                Field(cc => cc.Version).Description("The version of the content collection.");
                Field <ContentTypeType>("ContentType");

                var contentItemType = new ContentItemType(contentCollection, languages, defaultLanguage);
                var itemsType       = new ListGraphType(contentItemType);
                this.Field("items",
                           itemsType,
                           arguments: new QueryArguments(
                               new QueryArgument <StringGraphType>()
                {
                    Name = "contentKeyStartsWith"
                },
                               new QueryArgument <IntGraphType>()
                {
                    Name = "first"
                },
                               new QueryArgument <IntGraphType>()
                {
                    Name = "offset"
                }
                               ),
                           resolve: ctx =>
                {
                    var collection = ctx.Source as ContentCollection;
                    if (collection != null)
                    {
                        var contentStore     = getContentStore();
                        var contentItemQuery = new ContentItemQuery
                        {
                            AppId                = contentCollection.ContentType.AppId,
                            CollectionId         = collection.Id,
                            ContentKeyStartsWith = ctx.GetArgument <string>("contentKeyStartsWith"),
                            First                = ctx.GetArgument <int?>("first"),
                            Offset               = ctx.GetArgument <int?>("offset")
                        };
                        return(contentStore.GetContentItems(contentItemQuery));
                    }
                    else
                    {
                        return(null);
                    }
                });
            }
            else
            {
                // TODO: log that a graphQL name could not be generated.
            }
        }
コード例 #2
0
        public Task <ContentItem[]> GetContentItems(ContentItemQuery query)
        {
            var q = _liteRepository.Query <ContentItem>();

            if (!string.IsNullOrEmpty(query.AppId))
            {
                q = q.Where(ci => ci.AppId == query.AppId);
            }
            if (!string.IsNullOrEmpty(query.Id))
            {
                q = q.Where(ci => ci.Id == query.Id);
            }
            if (!string.IsNullOrEmpty(query.CollectionId))
            {
                q = q.Where(ci => ci.CollectionId == query.CollectionId);
            }
            if (!string.IsNullOrEmpty(query.ContentKey))
            {
                q = q.Where(ci => ci.ContentKey == query.ContentKey);
            }
            if (!string.IsNullOrEmpty(query.ContentKeyStartsWith))
            {
                q = q.Where(ci => ci.ContentKey.StartsWith(query.ContentKeyStartsWith));
            }

            switch (query.OrderBy)
            {
            case ContentItemQuery.ContentItemsOrderBy.LastModifiedAtDescending:
                q = q.OrderByDescending(ci => ci.LastModifiedAt);
                break;

            case ContentItemQuery.ContentItemsOrderBy.ContentKey:
                q = q.OrderBy(ci => ci.ContentKey);
                break;
            }

            ILiteQueryableResult <ContentItem> result = q;

            if (query.Offset.HasValue)
            {
                result = result.Skip(query.Offset.Value);
            }
            if (query.First.HasValue)
            {
                result = result.Limit(query.First.Value);
            }

            return(Task.FromResult(result.ToArray()));
        }
コード例 #3
0
        public async Task <ContentItem[]> GetContentItems(ContentItemQuery query)
        {
            if (String.IsNullOrEmpty(query.AppId))
            {
                throw new ArgumentException("NoDbStorage always requires the AppId property");
            }
            var contentItems = await _contentItemQueries.GetAllAsync(query.AppId);

            if (!string.IsNullOrEmpty(query.Id))
            {
                contentItems = contentItems.Where(ci => ci.Id == query.Id);
            }
            if (!string.IsNullOrEmpty(query.CollectionId))
            {
                contentItems = contentItems.Where(ci => ci.CollectionId == query.CollectionId);
            }
            if (!string.IsNullOrEmpty(query.ContentKey))
            {
                contentItems = contentItems.Where(ci => string.Equals(ci.ContentKey, query.ContentKey, StringComparison.InvariantCultureIgnoreCase));
            }
            if (!string.IsNullOrEmpty(query.ContentKeyStartsWith))
            {
                contentItems = contentItems.Where(ci => ci.ContentKey.StartsWith(query.ContentKeyStartsWith, StringComparison.InvariantCultureIgnoreCase));
            }

            switch (query.OrderBy)
            {
            case ContentItemQuery.ContentItemsOrderBy.LastModifiedAtDescending:
                contentItems = contentItems.OrderByDescending(ci => ci.LastModifiedAt);
                break;

            case ContentItemQuery.ContentItemsOrderBy.ContentKey:
                contentItems = contentItems.OrderBy(ci => ci.ContentKey);
                break;
            }

            if (query.Offset.HasValue)
            {
                contentItems = contentItems.Skip(query.Offset.Value);
            }
            if (query.First.HasValue)
            {
                contentItems = contentItems.Take(query.First.Value);
            }
            return(contentItems.ToArray());
        }