Skip to content

Commit

Permalink
chore: rewrite springdoc with parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Jul 29, 2024
1 parent d916b23 commit ceff337
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/run/halo/moments/MomentEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public RouterFunction<ServerResponse> endpoint() {
.response(responseBuilder()
.implementation(ListResult.generateGenericClass(ListedMoment.class))
);
MomentQuery.buildParameters(builder);
})
.GET("moments/{name}", this::getMoment,
builder -> builder.operationId("GetMoment")
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/run/halo/moments/MomentQuery.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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))
;
}

}
7 changes: 7 additions & 0 deletions src/main/java/run/halo/moments/uc/UcMomentEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ public RouterFunction<ServerResponse> 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))
)
Expand Down

0 comments on commit ceff337

Please sign in to comment.