Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any document about the entity CRUD restful apis #73

Open
timiil opened this issue Dec 1, 2021 · 7 comments
Open

Any document about the entity CRUD restful apis #73

timiil opened this issue Dec 1, 2021 · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@timiil
Copy link

timiil commented Dec 1, 2021

hi, as the title say, for now, i can find is :

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);
        }

any detail documentation about these above apis ?

thanks very much !

@antifree antifree added documentation Improvements or additions to documentation question Further information is requested labels Dec 1, 2021
@antifree
Copy link
Member

antifree commented Dec 5, 2021

Unfortunately, we don't have any documentation yet.

Currently, you can figure it out by observing (with the Developer Tools panel in your browser) the requests sent from the client-side to the backend in any of our sample projects.

We will let you know when we publish the docs about the API

@timiil
Copy link
Author

timiil commented Dec 6, 2021

the most complex is the 'GetEntities' action, i can not figurate out ...

curl -X POST \
 http://localhost:5285/api/easydata/models/__default/crud/Store/fetch \
  -H 'Content-Type: application/json' \
  -d '{
 "filters":[
  {"class":"Store"},{"StoreId":"1525"}
 ]
}

the result is :

{
    "result": "error",
    "message": "Value cannot be null. (Parameter 'key')"
}

any quick help to this endpoint? thanks you very much !

@korzh
Copy link
Collaborator

korzh commented Dec 6, 2021

fetch is a POST request that has the following structure of a payload:

{
    limit: <number of records to fetch in this "chunk">,
    offset: <the row number we should start from>,
    needTotal: true|false, //should the server-side calculate the total number of records as well
    lookup: true|false, //indicates whether this is a request for "lookup" data (for example we as for the list of customers while editing an order 
    filters?: [ <filter1>, <filter2>, ... ]
}

Here each filter is an object with 2 properties:

{
  class: '__substring', //The type of the filter. Only "__substring" type is supported for now
  value: 'any string value', //The value of the filter. In this case, the substring we filter our result set by.
}

@timiil
Copy link
Author

timiil commented Dec 6, 2021

thanka a lot for the info

@fasteddys
Copy link

Please add some documentation also on the understanding on how its logic is working` so we can use it and adapt it into the solution correctly.

If possible include a picture on the components and what pieces/where to integrate inside the solution. I think this will help many developers for you

@korzh
Copy link
Collaborator

korzh commented Dec 24, 2021

Please add some documentation also on the understanding on how its logic is working` so we can use it and adapt it into the solution correctly.

We are going to release version 1.4.0 soon. There will be a few changes in the API. After that, we plan to publish the documentation for the library with an API reference and a detailed description of how things work.

@korzh korzh self-assigned this Dec 24, 2021
@karasuma27
Copy link

Hi korzh, is the API doc up now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants