I'm using the quarkus-hibernate-orm-rest-data-panache extension to generate CRUD's, and in the endpoint that lists the records, the pagination links are not correct. This only becomes evident when I use a filter and/or custom query. Reviewing the source code of the rest-data-panache extension I discovered the reason:
The reason is that this SQL query to obtain the total number of records must also consider the filters and/or custom queries that I apply as part of my query-params, and in this way both queries (for the total and list) will be affected by the filters and/or queries:
In this second source code fragment you can see that the query and dataParams parameters are being injected, both parameters should also be used to obtain the total.
Describe the bug
I'm using the quarkus-hibernate-orm-rest-data-panache extension to generate CRUD's, and in the endpoint that lists the records, the pagination links are not correct. This only becomes evident when I use a filter and/or custom query. Reviewing the source code of the rest-data-panache extension I discovered the reason:
Class: io.quarkus.rest.data.panache.deployment.methods.ListMethodImplementor.java Line: 232 Version: 3.11.2
The reason is that this SQL query to obtain the total number of records must also consider the filters and/or custom queries that I apply as part of my query-params, and in this way both queries (for the total and list) will be affected by the filters and/or queries:
Class: io.quarkus.rest.data.panache.deployment.methods.ListMethodImplementor.java Line: 361 Version: 3.11.2
In this second source code fragment you can see that the query and dataParams parameters are being injected, both parameters should also be used to obtain the total.
Expected behavior
Records in my database:
Scenery 1:
Endpoint consumption without filtering parameters: https://api.jimyx,dev/users?size=2
Headers obtained: Link: https://api.jimyx,dev/users?page=0&size=2; rel="first" Link: https://api.jimyx,dev/users?page=1&size=2; rel="last" Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"
Scenery 2:
Endpoint consumption with filtering parameters: https://api.jimyx,dev/users?size=2&createdBy=Nikola
Headers obtained: Link: https://api.jimyx,dev/users?page=0&size=2; rel="first" Link: https://api.jimyx,dev/users?page=0&size=2; rel="last"
Actual behavior
Records in my database:
Scenery 1:
Endpoint consumption without filtering parameters: https://api.jimyx,dev/users?size=2
Headers obtained: Link: https://api.jimyx,dev/users?page=0&size=2; rel="first" Link: https://api.jimyx,dev/users?page=1&size=2; rel="last" Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"
Scenery 2:
Endpoint consumption with filtering parameters: https://api.jimyx,dev/users?size=2&createdBy=Nikola
Headers obtained: Link: https://api.jimyx,dev/users?page=0&size=2; rel="first" Link: https://api.jimyx,dev/users?page=1&size=2; rel="last" Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response