public async Task <IActionResult> GetContent(string app, string name, Guid id) { var content = await contentQuery.FindContentAsync(Context, name, id); var response = ContentDto.FromContent(Context, content, this); if (controllerOptions.EnableSurrogateKeys) { Response.Headers["Surrogate-Key"] = content.ToSurrogateKey(); } Response.Headers[HeaderNames.ETag] = content.ToEtag(); return(Ok(response)); }
public async Task <IActionResult> GetContent(string app, string name, Guid id) { var context = Context().WithSchemaName(name); var content = await contentQuery.FindContentAsync(context, id); 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)); }
public async Task <IActionResult> GetContent(string name, Guid id) { var content = await contentQuery.FindContentAsync(App, name, User, id); var response = SimpleMapper.Map(content.Content, new ContentDto()); if (content.Content.Data != null) { var isFrontendClient = User.IsFrontendClient(); response.Data = content.Content.Data.ToApiModel(content.Schema.SchemaDef, App.LanguagesConfig, !isFrontendClient); } Response.Headers["ETag"] = new StringValues(content.Content.Version.ToString()); return(Ok(response)); }
public async Task <IActionResult> GetContent(string app, string name, Guid id) { var(schema, entity) = await contentQuery.FindContentAsync(App, name, User, id); var response = SimpleMapper.Map(entity, new ContentDto()); if (entity.Data != null) { var isFrontendClient = User.IsFrontendClient(); response.Data = entity.Data.ToApiModel(schema.SchemaDef, App.LanguagesConfig, !isFrontendClient); } Response.Headers["ETag"] = entity.Version.ToString(); Response.Headers["Surrogate-Key"] = entity.Id.ToString(); return(Ok(response)); }
public virtual async Task <IContentEntity> FindContentAsync(Guid schemaId, Guid id) { var content = cachedContents.GetOrDefault(id); if (content == null) { content = await contentQuery.FindContentAsync(context, schemaId.ToString(), id); if (content != null) { cachedContents[content.Id] = content; } } return(content); }
public async Task <IContentEntity> FindContentAsync(Guid schemaId, Guid id) { var content = cachedContents.GetOrDefault(id); if (content == null) { content = await contentQuery.FindContentAsync(context.WithSchemaId(schemaId), id); if (content != null) { cachedContents[content.Id] = content; } } return(content); }
public async Task <IContentEntity> FindContentAsync(Guid schemaId, Guid id) { var content = cachedContents.GetOrDefault(id); if (content == null) { content = (await contentQuery.FindContentAsync(app, schemaId.ToString(), user, id).ConfigureAwait(false)).Content; if (content != null) { cachedContents[content.Id] = content; } } return(content); }
public async Task Should_return_single_content_when_finding_content() { var contentId = Guid.NewGuid(); var content = CreateContent(contentId, Guid.Empty, Guid.Empty); var query = $@" query {{ findMySchemaContent(id: ""{contentId}"") {{ id version created createdBy lastModified lastModifiedBy url data {{ myString {{ iv }} myNumber {{ iv }} myBoolean {{ iv }} myDatetime {{ iv }} myJson {{ iv }} myGeolocation {{ iv }} }} }} }}"; A.CallTo(() => contentQuery.FindContentAsync(app, schema.Id.ToString(), user, contentId)) .Returns((schema, content)); var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, version = 1, created = content.Created.ToDateTimeUtc(), createdBy = "subject:user1", lastModified = content.LastModified.ToDateTimeUtc(), lastModifiedBy = "subject:user2", url = $"contents/my-schema/{content.Id}", data = new { myString = new { iv = "value" }, myNumber = new { iv = 1 }, myBoolean = new { iv = true }, myDatetime = new { iv = content.LastModified.ToDateTimeUtc() }, myJson = new { iv = new { value = 1 } }, myGeolocation = new { iv = new { latitude = 10, longitude = 20 } } } } } }; AssertJson(expected, new { data = result.Data }); }