From ceff3372c72fea45f47ad713654e45722387a14f Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Mon, 29 Jul 2024 15:10:28 +0800 Subject: [PATCH 1/2] chore: rewrite springdoc with parameter --- .../java/run/halo/moments/MomentEndpoint.java | 1 + .../java/run/halo/moments/MomentQuery.java | 49 +++++++++++++++++++ .../run/halo/moments/uc/UcMomentEndpoint.java | 7 +++ 3 files changed, 57 insertions(+) diff --git a/src/main/java/run/halo/moments/MomentEndpoint.java b/src/main/java/run/halo/moments/MomentEndpoint.java index 42ae3de..2cc350d 100644 --- a/src/main/java/run/halo/moments/MomentEndpoint.java +++ b/src/main/java/run/halo/moments/MomentEndpoint.java @@ -48,6 +48,7 @@ public RouterFunction endpoint() { .response(responseBuilder() .implementation(ListResult.generateGenericClass(ListedMoment.class)) ); + MomentQuery.buildParameters(builder); }) .GET("moments/{name}", this::getMoment, builder -> builder.operationId("GetMoment") diff --git a/src/main/java/run/halo/moments/MomentQuery.java b/src/main/java/run/halo/moments/MomentQuery.java index fa94bf7..3502802 100644 --- a/src/main/java/run/halo/moments/MomentQuery.java +++ b/src/main/java/run/halo/moments/MomentQuery.java @@ -1,23 +1,29 @@ package run.halo.moments; +import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder; import static run.halo.app.extension.index.query.QueryFactory.all; import static run.halo.app.extension.index.query.QueryFactory.and; import static run.halo.app.extension.index.query.QueryFactory.contains; import static run.halo.app.extension.index.query.QueryFactory.equal; import static run.halo.app.extension.index.query.QueryFactory.greaterThanOrEqual; import static run.halo.app.extension.index.query.QueryFactory.lessThanOrEqual; +import static run.halo.app.extension.router.QueryParamBuildUtil.sortParameter; import static run.halo.app.extension.router.selector.SelectorUtil.labelAndFieldSelectorToListOptions; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.Schema; import java.time.Instant; import org.apache.commons.lang3.StringUtils; +import org.springdoc.core.fn.builders.operation.Builder; import org.springframework.data.domain.Sort; import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; +import run.halo.app.core.extension.content.Post; import run.halo.app.extension.ListOptions; import run.halo.app.extension.PageRequest; import run.halo.app.extension.PageRequestImpl; +import run.halo.app.extension.router.IListRequest; import run.halo.app.extension.router.SortableRequest; import run.halo.app.extension.router.selector.FieldSelector; @@ -141,4 +147,47 @@ private Boolean convertBooleanOrNull(String value) { private Instant convertInstantOrNull(String timeStr) { return StringUtils.isBlank(timeStr) ? null : Instant.parse(timeStr); } + + public static void buildParameters(Builder builder) { + IListRequest.buildParameters(builder); + builder.parameter(sortParameter()) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("keyword") + .description("Moments filtered by keyword.") + .implementation(String.class) + .required(false)) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("ownerName") + .description("Owner name.") + .implementation(String.class) + .required(false)) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("tag") + .description("Moment tag.") + .implementation(String.class) + .required(false)) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("visible") + .description("Moment visible.") + .implementation(Moment.MomentVisible.class) + .required(false)) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("startDate") + .implementation(Instant.class) + .description("Moment start date.") + .required(false)) + .parameter(parameterBuilder() + .in(ParameterIn.QUERY) + .name("endDate") + .implementation(Instant.class) + .description("Moment end date.") + .required(false)) + ; + } + } diff --git a/src/main/java/run/halo/moments/uc/UcMomentEndpoint.java b/src/main/java/run/halo/moments/uc/UcMomentEndpoint.java index 727d83d..3e7a166 100644 --- a/src/main/java/run/halo/moments/uc/UcMomentEndpoint.java +++ b/src/main/java/run/halo/moments/uc/UcMomentEndpoint.java @@ -58,11 +58,18 @@ public RouterFunction endpoint() { .response(responseBuilder() .implementation(ListResult.generateGenericClass(ListedMoment.class)) ); + MomentQuery.buildParameters(builder); }) .GET("moments/{name}", this::getMyMoment, builder -> builder.operationId("GetMyMoment") .description("Get a My Moment.") .tag(tag) + .parameter(parameterBuilder() + .name("name") + .in(ParameterIn.PATH) + .required(true) + .implementation(String.class) + ) .response(responseBuilder() .implementation(Moment.class)) ) From 85a7d350c0f0a54639135da2366a4701f4bdf666 Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Mon, 29 Jul 2024 15:12:28 +0800 Subject: [PATCH 2/2] chore: rewrite springdoc with parameter --- src/main/java/run/halo/moments/MomentQuery.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/run/halo/moments/MomentQuery.java b/src/main/java/run/halo/moments/MomentQuery.java index 3502802..d580437 100644 --- a/src/main/java/run/halo/moments/MomentQuery.java +++ b/src/main/java/run/halo/moments/MomentQuery.java @@ -19,7 +19,6 @@ import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; -import run.halo.app.core.extension.content.Post; import run.halo.app.extension.ListOptions; import run.halo.app.extension.PageRequest; import run.halo.app.extension.PageRequestImpl;