private static readonly Endpoint[] _routing =
{
new Endpoint(DataAction.GetModel, @"^/models/([^/]+?)$", "GET"),
new Endpoint(DataAction.GetEntities, @"^/models/([^/]+?)/crud/([^/]+?)/fetch$", "POST"),
new Endpoint(DataAction.GetEntity, @"^/models/([^/]+?)/crud/([^/]+?)/fetch/([^/]+?)$", "GET"),
new Endpoint(DataAction.CreateEntity, @"^/models/([^/]+?)/crud/([^/]+?)/create$", "POST"),
new Endpoint(DataAction.UpdateEntity,@"^/models/([^/]+?)/crud/([^/]+?)/update/([^/]+?)$", "POST"),
new Endpoint(DataAction.DeleteEntity, @"^/models/([^/]+?)/crud/([^/]+?)/delete/([^/]+?)$", "POST")
};
...
public virtual async Task HandleGetEntitiesAsync(string modelId, string entityContainer, CancellationToken ct = default)
{
int? offset = null;
int? fetch = null;
bool isLookup = false;
IEnumerable<EasyFilter> filters = null;
bool needTotal = false;
JObject requestParams;
using (var requestReader = new HttpRequestStreamReader(HttpContext.Request.Body, Encoding.UTF8))
using (var jsonReader = new JsonTextReader(requestReader)) {
requestParams = await JObject.LoadAsync(jsonReader, ct);
}
if (requestParams.TryGetValue("offset", out var value)) {
offset = value.ToObject<int?>();
}
if (requestParams.TryGetValue("limit", out value)) {
fetch = value.ToObject<int?>();
}
if (requestParams.TryGetValue("needTotal", out value)) {
needTotal = value.ToObject<bool>();
}
if (requestParams.TryGetValue("lookup", out value)) {
isLookup = value.ToObject<bool>();
}
if (requestParams.TryGetValue("filters", out value) && value.HasValues) {
filters = await GetFiltersAsync(modelId, (JArray)value, ct);
}
long? total = null;
if (needTotal) {
total = await Manager.GetTotalEntitiesAsync(modelId, entityContainer, filters, isLookup, ct);
}
var sorters = await Manager.GetDefaultSortersAsync(modelId, entityContainer);
var result = await Manager.GetEntitiesAsync(modelId, entityContainer, filters, sorters, isLookup, offset, fetch);
await WriteOkJsonResponseAsync(HttpContext, async (jsonWriter, cancellationToken) => {
await WriteGetEntitiesResponseAsync(jsonWriter, result, total, cancellationToken);
}, ct);
}