public async Task <IActionResult> GetContents(string app, string name, [FromQuery] string ids = null) { var schema = await contentQuery.GetSchemaOrThrowAsync(Context, name); var contents = await contentQuery.QueryAsync(Context, name, Q.Empty.WithIds(ids).WithODataQuery(Request.QueryString.ToString())); var response = Deferred.AsyncResponse(async() => { return(await ContentsDto.FromContentsAsync(contents, Context, this, schema, contentWorkflow)); }); if (ShouldProvideSurrogateKeys(contents)) { Response.Headers["Surrogate-Key"] = contents.ToSurrogateKeys(); } Response.Headers[HeaderNames.ETag] = contents.ToEtag(); return(Ok(response)); }
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)); }
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)); }
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)); }
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)); }
public async Task <IActionResult> GetContents(string name, [FromQuery] bool nonPublished = false, [FromQuery] bool hidden = false) { var schemaEntity = await schemas.FindSchemaByNameAsync(AppId, name); if (schemaEntity == null) { return(NotFound()); } var languages = new HashSet <Language>(App.Languages); var query = Request.QueryString.ToString(); var taskForContents = contentRepository.QueryAsync(schemaEntity.Id, nonPublished, query, languages); var taskForCount = contentRepository.CountAsync(schemaEntity.Id, nonPublished, query, languages); await Task.WhenAll(taskForContents, taskForCount); var model = new ContentsDto { Total = taskForCount.Result, Items = taskForContents.Result.Take(200).Select(x => { var itemModel = SimpleMapper.Map(x, new ContentDto()); if (x.Data != null) { itemModel.Data = x.Data.ToApiModel(schemaEntity.Schema, App.Languages, App.MasterLanguage); } return(itemModel); }).ToArray() }; return(Ok(model)); }
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 isFrontendClient = User.IsFrontendClient(); var result = idsList?.Count > 0 ? await contentQuery.QueryAsync(App, name, User, archived, idsList) : await contentQuery.QueryAsync(App, name, User, archived, Request.QueryString.ToString()); var response = new ContentsDto { Total = result.Total, Items = result.Take(200).Select(item => SimpleMapper.Map(item, new ContentDto { Data = item.Data })).ToArray() }; Response.Headers["Surrogate-Key"] = string.Join(" ", response.Items.Select(x => x.Id)); return(Ok(response)); }
private bool ShouldProvideSurrogateKeys(ContentsDto response) { return(controllerOptions.Value.EnableSurrogateKeys && response.Items.Length <= controllerOptions.Value.MaxItemsForSurrogateKeys); }