From 6dc634e511c828441989dd192801f357c073954e Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 9 Jan 2024 13:58:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=D0=B2=D0=BE=D0=B9=20=D0=BC=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haiti/filter/quarkus/QuarkusFilter.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) 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 + ); + } + }