FINERACT-2169: Apply dto in api and clean up unnecessary swagger;
This commit is contained in:
committed by
Adam Saghy
parent
2f5ae610d1
commit
707fe3d0e5
Vendored
+8
-26
@@ -20,7 +20,6 @@ package org.apache.fineract.infrastructure.cache.api;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||||
@@ -32,22 +31,16 @@ import jakarta.ws.rs.GET;
|
|||||||
import jakarta.ws.rs.PUT;
|
import jakarta.ws.rs.PUT;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.Context;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.UriInfo;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||||
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
import org.apache.fineract.infrastructure.cache.data.CacheData;
|
import org.apache.fineract.infrastructure.cache.data.CacheData;
|
||||||
|
import org.apache.fineract.infrastructure.cache.data.request.CacheRequest;
|
||||||
import org.apache.fineract.infrastructure.cache.service.RuntimeDelegatingCacheManager;
|
import org.apache.fineract.infrastructure.cache.service.RuntimeDelegatingCacheManager;
|
||||||
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
|
|
||||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
|
||||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
@@ -63,12 +56,10 @@ import org.springframework.stereotype.Component;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CacheApiResource {
|
public class CacheApiResource {
|
||||||
|
|
||||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(List.of("id"));
|
|
||||||
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "CACHE";
|
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "CACHE";
|
||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final DefaultToApiJsonSerializer<CacheData> toApiJsonSerializer;
|
private final DefaultToApiJsonSerializer<CacheData> toApiJsonSerializer;
|
||||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
|
||||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
@Qualifier("runtimeDelegatingCacheManager")
|
@Qualifier("runtimeDelegatingCacheManager")
|
||||||
private final RuntimeDelegatingCacheManager cacheService;
|
private final RuntimeDelegatingCacheManager cacheService;
|
||||||
@@ -76,29 +67,20 @@ public class CacheApiResource {
|
|||||||
@GET
|
@GET
|
||||||
@Operation(summary = "Retrieve Cache Types", description = "Returns the list of caches.\n" + "\n" + "Example Requests:\n" + "\n"
|
@Operation(summary = "Retrieve Cache Types", description = "Returns the list of caches.\n" + "\n" + "Example Requests:\n" + "\n"
|
||||||
+ "caches")
|
+ "caches")
|
||||||
@ApiResponses({
|
public Collection<CacheData> retrieveAll() {
|
||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CacheApiResourceSwagger.GetCachesResponse.class)))) })
|
|
||||||
public String retrieveAll(@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||||
|
return cacheService.retrieveAll();
|
||||||
final Collection<CacheData> codes = this.cacheService.retrieveAll();
|
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
|
||||||
return this.toApiJsonSerializer.serialize(settings, codes, RESPONSE_DATA_PARAMETERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Operation(summary = "Switch Cache", description = "Switches the cache to chosen one.")
|
@Operation(summary = "Switch Cache", description = "Switches the cache to chosen one.")
|
||||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CacheApiResourceSwagger.PutCachesRequest.class)))
|
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CacheRequest.class)))
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CacheApiResourceSwagger.PutCachesResponse.class))) })
|
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CacheApiResourceSwagger.PutCachesResponse.class))) })
|
||||||
public String switchCache(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
public CommandProcessingResult switchCache(@Parameter(hidden = true) CacheRequest cacheRequest) {
|
||||||
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCache()
|
||||||
|
.withJson(toApiJsonSerializer.serialize(cacheRequest)).build();
|
||||||
|
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCache().withJson(apiRequestBodyAsJson).build();
|
return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
|
||||||
|
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-24
@@ -19,7 +19,6 @@
|
|||||||
package org.apache.fineract.infrastructure.cache.api;
|
package org.apache.fineract.infrastructure.cache.api;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sanyam on 28/7/17.
|
* Created by sanyam on 28/7/17.
|
||||||
@@ -30,29 +29,6 @@ final class CacheApiResourceSwagger {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema(description = "GetCachesResponse")
|
|
||||||
public static final class GetCachesResponse {
|
|
||||||
|
|
||||||
private GetCachesResponse() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData cacheType;
|
|
||||||
public boolean enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Schema(description = "PutCachesRequest")
|
|
||||||
public static final class PutCachesRequest {
|
|
||||||
|
|
||||||
private PutCachesRequest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Schema(example = "2")
|
|
||||||
public Long cacheType;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Schema(description = "PutCachesResponse")
|
@Schema(description = "PutCachesResponse")
|
||||||
public static final class PutCachesResponse {
|
public static final class PutCachesResponse {
|
||||||
|
|
||||||
|
|||||||
Vendored
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.infrastructure.cache.data.request;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public record CacheRequest(Long cacheType) implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user