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

Allow Sort to be empty #20329

Closed
acaciobrito opened this issue Sep 22, 2021 · 3 comments · Fixed by #20459
Closed

Allow Sort to be empty #20329

acaciobrito opened this issue Sep 22, 2021 · 3 comments · Fixed by #20459
Labels
area/panache good first issue Good for newcomers kind/enhancement New feature or request
Milestone

Comments

@acaciobrito
Copy link

acaciobrito commented Sep 22, 2021

Description

I am writing amazon lambdas using quarkus-amazon-lambda-rest, quarkus-resteasy-jackson and quarkus-hibernate-orm-panache
I have one rest endpoint that will return me a list of the entities. But I need to be able to sort that list based on a query param.

Right now my query param is a list of string where I receive 'columnName,(ASC or DSC)'

The Sort class from io.quarkus.panache.common has it constructor as private.
It requires the Sort object to always have some column. We should have way to be able to create a Sort object without defining a column. Pretty much to what spring does with Pageable.Sort.

For example, this isn't allowed

 Sort sort = new Sort();

    for (String s : sortQuery) {
      String sortColumn = s.split(",")[0];
      String sortOrder = s.split(",")[1];

      sort.and(sortColumn,
          sortOrder.equalsIgnoreCase("ASC") ? Direction.Ascending : Direction.Descending);
    }
return personRepository.findByName(name, sort) 

Implementation ideas

Either allow the constructor on Sort to be public or create an static method .empty().

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 22, 2021

/cc @FroMage, @loicmathieu

@loicmathieu
Copy link
Contributor

@FroMage empty sort is already possible via Sort.by() as we use a varargs but it's not very discoverable so adding Sort.emtpy() seems to be a good addition with a discoverable name and a straighforward implementation (delegate to Sort.by()).
WDYT ?

@geoand
Copy link
Contributor

geoand commented Sep 23, 2021

Sounds reasonable to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache good first issue Good for newcomers kind/enhancement New feature or request
Projects
None yet
3 participants