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 b36a8aa..60d26e2 100644 --- a/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java +++ b/src/main/java/dev/struchkov/haiti/filter/quarkus/QuarkusFilter.java @@ -10,13 +10,16 @@ import dev.struchkov.haiti.filter.jooq.sort.SortType; import dev.struchkov.haiti.utils.Inspector; import io.smallrye.mutiny.Uni; import io.vertx.mutiny.pgclient.PgPool; +import io.vertx.mutiny.sqlclient.Row; import org.jooq.DSLContext; import org.jooq.Query; import org.jooq.conf.ParamType; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -103,18 +106,25 @@ public class QuarkusFilter { return this; } - public Uni> build(Class idType, String idField) { - final Query query = jooqFilter.generateQuery(tableName + "." + idField); + public Uni> build(Function mapper, String... idFields) { + final Query query = jooqFilter.generateQuery(Arrays.stream(idFields).map(field -> tableName + "." + field).toArray(String[]::new)); final String sql = query.getSQL(); return pgPool.preparedQuery(sql) .execute() .map(rows -> StreamSupport.stream(rows.spliterator(), false) - .map(row -> row.get(idType, idField)) + .map(mapper) .collect(Collectors.toList()) ); } + public Uni> build(Class idType, String idField) { + return build( + row -> row.get(idType, idField), + idField + ); + } + public Uni count() { final Query query = jooqFilter.generateCount(); final String sql = query.getSQL(); @@ -133,12 +143,14 @@ public class QuarkusFilter { }); } - public Uni> filterResult(Class idType, String idField) { - jooqFilter.groupBy(tableName + "." + idField); + public Uni> filterResult(Function mapper, String... idFields) { + for (String idField : idFields) { + jooqFilter.groupBy(tableName + "." + idField); + } // jooqFilter.groupBy(sortFieldNames); distinctCount = true; final Uni count = count(); - final Uni> content = build(idType, idField); + final Uni> content = build(mapper, idFields); return Uni.combine().all() .unis(count, content) .asTuple() @@ -156,4 +168,11 @@ public class QuarkusFilter { ); } + public Uni> filterResult(Class idType, String idField) { + return filterResult( + row -> row.get(idType, idField), + idField + ); + } + }