From 57a0e2bcbff03f0ea2b6f52a4d38cf60f8116593 Mon Sep 17 00:00:00 2001 From: Liu Rui Date: Sat, 28 Sep 2024 07:08:13 +0800 Subject: [PATCH] =?UTF-8?q?fix-ISelectAbility-=E4=BC=A0=E5=85=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E6=8E=92=E5=BA=8F=E5=AD=97=E6=AE=B5=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ximatai/muyun/test/core/TestNaked.java | 72 +++++++++++++++++++ .../muyun/ability/ITableCreateAbility.java | 2 - .../ability/curd/std/ISelectAbility.java | 4 +- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 my-boot/src/test/java/net/ximatai/muyun/test/core/TestNaked.java diff --git a/my-boot/src/test/java/net/ximatai/muyun/test/core/TestNaked.java b/my-boot/src/test/java/net/ximatai/muyun/test/core/TestNaked.java new file mode 100644 index 00000000..46b7483e --- /dev/null +++ b/my-boot/src/test/java/net/ximatai/muyun/test/core/TestNaked.java @@ -0,0 +1,72 @@ +package net.ximatai.muyun.test.core; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.common.mapper.TypeRef; +import jakarta.annotation.PostConstruct; +import jakarta.inject.Inject; +import jakarta.ws.rs.Path; +import net.ximatai.muyun.ability.IDatabaseAbility; +import net.ximatai.muyun.ability.IMetadataAbility; +import net.ximatai.muyun.ability.ITableCreateAbility; +import net.ximatai.muyun.ability.curd.std.ISelectAbility; +import net.ximatai.muyun.database.IDatabaseOperations; +import net.ximatai.muyun.database.builder.Column; +import net.ximatai.muyun.database.builder.TableWrapper; +import net.ximatai.muyun.test.testcontainers.PostgresTestResource; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; + +@QuarkusTest +@QuarkusTestResource(value = PostgresTestResource.class, restrictToAnnotatedClass = true) +public class TestNaked { + + @Test + void test() { + given() + .queryParam("sort", "t_create,desc") + .get("/demo/view") + .then() + .statusCode(200) + .extract() + .as(new TypeRef<>() { + }); + } +} + +@Path("/demo") +class Demo implements IDatabaseAbility, IMetadataAbility, ITableCreateAbility, ISelectAbility { + + @Inject + IDatabaseOperations databaseOperations; + + @PostConstruct + void init() { + create(getDatabaseOperations()); + } + + @Override + public String getSchemaName() { + return "public"; + } + + @Override + public String getMainTable() { + return "demo"; + } + + @Override + public IDatabaseOperations getDatabaseOperations() { + return databaseOperations; + } + + @Override + public TableWrapper getTableWrapper() { + return TableWrapper.withName("demo") + .setSchema(getSchemaName()) + .setPrimaryKey(Column.ID_POSTGRES) + .addColumn("v_name") + .addColumn("i_age"); + } +} diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/ITableCreateAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/ITableCreateAbility.java index e523c39d..91f5d9c1 100644 --- a/my-core/src/main/java/net/ximatai/muyun/ability/ITableCreateAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/ITableCreateAbility.java @@ -1,6 +1,5 @@ package net.ximatai.muyun.ability; -import jakarta.annotation.PostConstruct; import jakarta.transaction.Transactional; import net.ximatai.muyun.database.IDatabaseOperations; import net.ximatai.muyun.database.builder.TableBuilder; @@ -14,7 +13,6 @@ default void onTableCreated(boolean isFirst) { } @Transactional - @PostConstruct default void create(IDatabaseOperations db) { TableWrapper wrapper = getTableWrapper(); if (this instanceof ICommonBusinessAbility ability) { diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/curd/std/ISelectAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/curd/std/ISelectAbility.java index aa1ebd05..3e748a42 100644 --- a/my-core/src/main/java/net/ximatai/muyun/ability/curd/std/ISelectAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/curd/std/ISelectAbility.java @@ -136,7 +136,9 @@ default PageResult view(Integer page, if (strings.length > 1) { order = strings[1]; } - orderColumns.add(new SortColumn(strings[0], order)); + if (checkColumn(strings[0])) { + orderColumns.add(new SortColumn(strings[0], order)); + } }); }