Skip to content

Also include next and totalResources for nested resources. #1035

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

Closed
databrecht opened this issue Jul 20, 2021 · 7 comments
Closed

Also include next and totalResources for nested resources. #1035

databrecht opened this issue Jul 20, 2021 · 7 comments

Comments

@databrecht
Copy link

databrecht commented Jul 20, 2021

Is your feature request related to a problem? Please describe.
Retrieving a set of date entities returns, for example with:

  • api/v1/devices

Results in next links and total resources.

{
meta: {
  totalResources: 3
},
links: {
  self: "/api/v1/devices?page[size]=2",
  first: "/api/v1/devices?page[size]=2",
  last: "/api/v1/devices?page[size]=2&page[number]=2",
  next: "/api/v1/devices?page[size]=2&page[number]=2"
},
data: [...

However, when calling a nested endpoint which contains a list of data entities such as:

  • api/v1/locations//devices

It seems that totalResources as well as the next link is not included in the result which makes it hard for the client to paginate. Pagination works (the query parameters can be used) but the links and information of the total number of resources is omitted in the json result.

{
links: {
  self: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices",
  first: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices"
},
  data: [...
{

We have noticed that there is no count query executed for these kind of URIs which might indicate that this is intended and therefore I didn't log it as a bug.

Describe the solution you'd like
Results in nested results that are consistent with an entity list that is retrieve via the direct devices call. A next link probably is definitely desired since there is a prev link if you would would grab a page further in the order:

{
links: {
  self: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1&page[number]=2",
  first: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1",
  prev: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1"
},
data: [...

So it feels inconsistent that you can use the links to get the prev yet have to construct the next links yourself.
The totalResources would definitely be convenient as well since it's more consistent to the other results.

Describe alternatives you've considered
Currently we will postprocess the json result and add the information ourselves, if there is a better solution, please advise.

Additional context
Version 4.2.0

@bart-degreed
Copy link
Contributor

Hi @databrecht, thanks for bringing this up. Unless I misunderstood, this is a known limitation, tracked at #1010. If that's the case, can you please upvote that issue, so that I can close this one as a duplicate?

@bart-degreed
Copy link
Contributor

An alternative to post-processing would be to execute the COUNT(*) by yourself, inject IPaginationContext, and set its TotalResourceCount property from a custom controller/service/repository.

@databrecht
Copy link
Author

My apologies, I didn't find that ticket. Thanks for the advice! Feel free to close if it doesn't add any information to 1010

@bart-degreed
Copy link
Contributor

Closing as duplicate of #1010.

@bart-degreed
Copy link
Contributor

@databrecht This is now fixed in the master branch. It would be great if you can try it out and let us know if that solves your case.

@databrecht
Copy link
Author

That's awesome, I'll look into it. However, at least this week I'm working on a deadline of another project. Once I have some time for the other project I'll test it out.

@databrecht
Copy link
Author

databrecht commented Dec 23, 2021

Only got to it now, I upgraded to the latest version to test (5.0.0-pre1). It works now, my case is solved and I can remove my workarounds, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants