public async Task InvokeAsync( HttpContext context, ISchemaStorage schemaStorage, JsonService jsonService) { ContentSchema schema; if (context.GetRouteValue("id") is string) { Guid id = Guid.Parse((string)context.GetRouteValue("id")); schema = await schemaStorage.GetContentSchemaAsync(id); } else { string name = (string)context.GetRouteValue("name"); schema = await schemaStorage.GetContentSchemaAsync(name); } RestContentSchema restSchema = schema.ToRest(); string json = jsonService.Serialize(restSchema); await context.Response.WriteAsync(json); }
public async Task InvokeAsync( HttpContext context, IContentStorage contentStore, ISchemaStorage schemaStorage, JsonService jsonService) { string schema = (string)context.GetRouteValue("schema"); QueryParameters queryParameters = await jsonService.Deserialize <QueryParameters>(context.Request.Body); ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema); QueryResult <ContentItem> contentItems = await contentStore.Query(schema, queryParameters); foreach (ContentItem contentItem in contentItems.Items) { contentItem.ApplySchema(schemaModel); } QueryResult <RestContentItem> resultQuery = new QueryResult <RestContentItem>() { Offset = contentItems.Offset, Count = contentItems.Count, TotalCount = contentItems.TotalCount, Items = contentItems.Items.Select(x => x.ToRest()).ToList() }; string json = jsonService.Serialize(resultQuery); await context.Response.WriteAsync(json); }
public async Task InvokeAsync( HttpContext context, IContentStorage contentStore, ISchemaStorage schemaStorage, JsonService jsonService) { Guid contentId = Guid.Parse((string)context.GetRouteValue("id")); string schema = (string)context.GetRouteValue("schema"); ContentItem result = await contentStore.GetContentItemAsync(schema, contentId); ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema); result.ApplySchema(schemaModel); RestContentItem restModel = result.ToRest(); string json = jsonService.Serialize(restModel); await context.Response.WriteAsync(json); }