-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API to fetch system configs by group
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
application/src/main/java/run/halo/app/core/endpoint/SystemConfigEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package run.halo.app.core.endpoint; | ||
|
||
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder; | ||
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder; | ||
import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder; | ||
|
||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.core.extension.endpoint.CustomEndpoint; | ||
import run.halo.app.extension.GroupVersion; | ||
import run.halo.app.infra.SystemConfigurableEnvironmentFetcher; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SystemConfigEndpoint implements CustomEndpoint { | ||
private final SystemConfigurableEnvironmentFetcher configurableEnvironmentFetcher; | ||
|
||
@Override | ||
public RouterFunction<ServerResponse> endpoint() { | ||
final var tag = "SystemConfigV1alpha1Console"; | ||
return SpringdocRouteBuilder.route() | ||
.GET("/systemconfigs/{group}", this::getConfigByGroup, | ||
builder -> builder.operationId("getSystemConfigByGroup") | ||
.description("Get system config by group") | ||
.tag(tag) | ||
.response(responseBuilder() | ||
.content(contentBuilder() | ||
.mediaType(MediaType.APPLICATION_JSON_VALUE) | ||
) | ||
.implementation(ObjectNode.class)) | ||
.parameter(parameterBuilder() | ||
.in(ParameterIn.PATH) | ||
.name("group") | ||
.required(true) | ||
.description("Group of the system config") | ||
) | ||
) | ||
.build(); | ||
} | ||
|
||
private Mono<ServerResponse> getConfigByGroup(ServerRequest request) { | ||
final var group = request.pathVariable("group"); | ||
return configurableEnvironmentFetcher.fetch(group, ObjectNode.class) | ||
.switchIfEmpty(Mono.fromSupplier(JsonNodeFactory.instance::objectNode)) | ||
.flatMap(json -> ServerResponse.ok().bodyValue(json)); | ||
} | ||
|
||
@Override | ||
public GroupVersion groupVersion() { | ||
return new GroupVersion("console.api.halo.run", "v1alpha1"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters