示例#1
0
        public async Task <OpenApiResult> GetContentSummary(IOpenApiContext context, string slug, string contentId, string ifNoneMatch)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(context.CurrentTenantId).ConfigureAwait(false);

            ContentSummary result = await contentStore.GetContentSummaryAsync(contentId, slug).ConfigureAwait(false);

            string etag = EtagHelper.BuildEtag(nameof(ContentSummary), result.ETag);

            // If the etag in the result matches ifNoneMatch then we return 304 Not Modified
            if (EtagHelper.IsMatch(ifNoneMatch, etag))
            {
                return(this.NotModifiedResult());
            }

            HalDocument resultDocument = this.contentSummaryMapper.Map(result, new ResponseMappingContext {
                TenantId = context.CurrentTenantId
            });

            OpenApiResult response = this.OkResult(resultDocument);

            response.Results.Add(HeaderNames.ETag, etag);

            // Since content is immutable we can allow clients to cache it indefinitely.
            response.Results.Add(HeaderNames.CacheControl, Constants.CacheControlHeaderOptions.NeverExpire);

            return(response);
        }
示例#2
0
        public async Task <OpenApiResult> GetContentHistory(string tenantId, string slug, int?limit, string continuationToken, string ifNoneMatch)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            ContentSummaries result = await contentStore.GetContentSummariesAsync(slug, limit ?? 20, continuationToken).ConfigureAwait(false);

            string resultEtag = EtagHelper.BuildEtag(nameof(ContentSummary), result.Summaries.Select(x => x.ETag).ToArray());

            // If the etag in the result matches ifNoneMatch then we return 304 Not Modified
            if (EtagHelper.IsMatch(ifNoneMatch, resultEtag))
            {
                return(this.NotModifiedResult());
            }

            var mappingContext = new ContentSummariesResponseMappingContext
            {
                ContinuationToken = continuationToken,
                Limit             = limit,
                Slug     = slug,
                TenantId = tenantId,
            };

            HalDocument resultDocument = this.contentSummariesMapper.Map(result, mappingContext);

            OpenApiResult response = this.OkResult(resultDocument);

            response.Results.Add(HeaderNames.ETag, resultEtag);

            return(response);
        }
        public async Task <OpenApiResult> CreateContent(string tenantId, string slug, CreateContentRequest body)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            Content request = body.AsContent(slug);

            Content result = await contentStore.StoreContentAsync(request).ConfigureAwait(false);

            string etag = EtagHelper.BuildEtag(nameof(Content), result.ETag);

            HalDocument resultDocument = this.contentMapper.Map(result, new ResponseMappingContext {
                TenantId = tenantId
            });

            WebLink location = resultDocument.GetLinksForRelation("self").First();

            OpenApiResult response = this.CreatedResult(location.Href, resultDocument);

            response.Results.Add(HeaderNames.ETag, etag);

            return(response);
        }