diff --git a/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java b/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java index aa85aac..e770360 100644 --- a/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java +++ b/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java @@ -14,6 +14,7 @@ import org.jooq.DSLContext; import org.jooq.Query; import org.jooq.conf.ParamType; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Consumer; @@ -29,6 +30,7 @@ public class QuarkusFilter { private final PgPool pgPool; private final CriteriaJooqFilter jooqFilter; private PageableOffset offset; + private final List sortFieldNames = new ArrayList<>(); private QuarkusFilter(PgPool pgPool, String table, DSLContext dslContext) { dslContext.settings().withParamType(ParamType.NAMED_OR_INLINED); @@ -79,17 +81,26 @@ public class QuarkusFilter { } public QuarkusFilter sort(SortContainer container) { - jooqFilter.sort(container); + if (container != null && container.getFieldName() != null) { + jooqFilter.sort(container); + sortFieldNames.add(container.getFieldName()); + } return this; } public QuarkusFilter sort(String field, SortType sortType) { - jooqFilter.sort(field, sortType); + if (field != null) { + jooqFilter.sort(field, sortType); + sortFieldNames.add(field); + } return this; } public QuarkusFilter sort(String field) { - jooqFilter.sort(field); + if (field != null) { + jooqFilter.sort(field); + sortFieldNames.add(field); + } return this; } @@ -125,6 +136,7 @@ public class QuarkusFilter { public Uni> filterResult(Class idType, String idField) { jooqFilter.groupBy(idField); + jooqFilter.groupBy(sortFieldNames); distinctCount = true; final Uni count = count(); final Uni> content = build(idType, idField);