Exemplo n.º 1
0
        public async Task <IActionResult> GetContent(string app, string name, Guid id)
        {
            var context = Context();
            var content = await contentQuery.FindContentAsync(context, name, id);

            var response = ContentDto.FromContent(content, context);

            if (controllerOptions.Value.EnableSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = content.Id.ToString();
            }

            Response.Headers[HeaderNames.ETag] = content.Version.ToString();

            return(Ok(response));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetContentVersion(string app, string name, Guid id, int version)
        {
            var context = Context().WithSchemaName(name);
            var content = await contentQuery.FindContentAsync(context, id, version);

            var response = ContentDto.FromContent(content, context.Base);

            Response.Headers["ETag"] = content.Version.ToString();

            if (controllerOptions.Value.EnableSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = content.Id.ToString();
            }

            return(Ok(response.Data));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] bool archived = false, [FromQuery] string ids = null)
        {
            var context = Context().WithArchived(archived).WithSchemaName(name);

            var result = await contentQuery.QueryAsync(context, Query.Empty.WithIds(ids).WithODataQuery(Request.QueryString.ToString()));

            var response = new ContentsDto
            {
                Total = result.Total,
                Items = result.Take(200).Select(x => ContentDto.FromContent(x, context.Base)).ToArray()
            };

            var options = controllerOptions.Value;

            if (options.EnableSurrogateKeys && response.Items.Length <= options.MaxItemsForSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = string.Join(" ", response.Items.Select(x => x.Id));
            }

            return(Ok(response));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] bool archived = false, [FromQuery] string ids = null)
        {
            var context = Context().WithArchived(archived);

            var result = await contentQuery.QueryAsync(context, name, Q.Empty.WithIds(ids).WithODataQuery(Request.QueryString.ToString()));

            var response = new ContentsDto
            {
                Total = result.Total,
                Items = result.Take(200).Select(x => ContentDto.FromContent(x, context)).ToArray()
            };

            if (controllerOptions.Value.EnableSurrogateKeys && response.Items.Length <= controllerOptions.Value.MaxItemsForSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = response.Items.ToSurrogateKeys();
            }

            Response.Headers["ETag"] = response.Items.ToManyEtag(response.Total);

            return(Ok(response));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetAllContents(string app, [FromQuery] string ids, [FromQuery] string status = null)
        {
            var context = Context().WithFrontendStatus(status);

            var result = await contentQuery.QueryAsync(context, Q.Empty.WithIds(ids).Ids);

            var response = new ContentsDto
            {
                Total = result.Count,
                Items = result.Take(200).Select(x => ContentDto.FromContent(x, context)).ToArray()
            };

            if (controllerOptions.Value.EnableSurrogateKeys && response.Items.Length <= controllerOptions.Value.MaxItemsForSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = response.Items.ToSurrogateKeys();
            }

            Response.Headers[HeaderNames.ETag] = response.Items.ToManyEtag();

            return(Ok(response));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] bool archived = false, [FromQuery] string ids = null)
        {
            HashSet <Guid> idsList = null;

            if (!string.IsNullOrWhiteSpace(ids))
            {
                idsList = new HashSet <Guid>();

                foreach (var id in ids.Split(','))
                {
                    if (Guid.TryParse(id, out var guid))
                    {
                        idsList.Add(guid);
                    }
                }
            }

            var context = Context().WithSchemaName(name).WithArchived(archived);

            var result =
                idsList?.Count > 0 ?
                await contentQuery.QueryAsync(context, idsList) :
                await contentQuery.QueryAsync(context, Request.QueryString.ToString());

            var response = new ContentsDto
            {
                Total = result.Total,
                Items = result.Take(200).Select(x => ContentDto.FromContent(x, context)).ToArray()
            };

            var options = controllerOptions.Value;

            if (options.EnableSurrogateKeys && response.Items.Length <= options.MaxItemsForSurrogateKeys)
            {
                Response.Headers["Surrogate-Key"] = string.Join(" ", response.Items.Select(x => x.Id));
            }

            return(Ok(response));
        }