vidakovic commented on code in PR #5613:
URL: https://github.com/apache/fineract/pull/5613#discussion_r2927191517
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/api/InterestRateChartsApiResource.java:
##########
@@ -46,143 +34,105 @@
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.HashSet;
import java.util.Set;
+import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
-import org.apache.fineract.commands.domain.CommandWrapper;
-import org.apache.fineract.commands.service.CommandWrapperBuilder;
-import
org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.command.core.CommandPipeline;
import org.apache.fineract.infrastructure.core.api.ApiParameterHelper;
-import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
-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.security.service.PlatformSecurityContext;
import
org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartCreateCommand;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartDeleteCommand;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartUpdateCommand;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartCreateRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartCreateResponse;
import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartData;
-import
org.apache.fineract.portfolio.interestratechart.service.InterestRateChartReadPlatformService;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartDeleteRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartDeleteResponse;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartUpdateRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartUpdateResponse;
+import
org.apache.fineract.portfolio.interestratechart.service.InterestRateChartReadService;
import org.springframework.stereotype.Component;
@Path("/v1/interestratecharts")
@Component
+@Consumes({ MediaType.APPLICATION_JSON })
+@Produces({ MediaType.APPLICATION_JSON })
@Tag(name = "Interest Rate Chart", description = "This defines an interest
rate scheme that can be associated to a term deposit product. This will have a
slab (band or range) of deposit periods and the associated interest rates
applicable along with incentives for each band.")
@RequiredArgsConstructor
public class InterestRateChartsApiResource {
- private final InterestRateChartReadPlatformService
chartReadPlatformService;
- private final PlatformSecurityContext context;
- private final DefaultToApiJsonSerializer<InterestRateChartData>
toApiJsonSerializer;
- private final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService;
- private final ApiRequestParameterHelper apiRequestParameterHelper;
- private static final Set<String>
INTERESTRATE_CHART_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(
- InterestRateChartApiConstants.localeParamName,
InterestRateChartApiConstants.dateFormatParamName, idParamName, nameParamName,
- descriptionParamName, fromDateParamName, endDateParamName,
chartSlabs, isPrimaryGroupingByAmountParamName));
+ private final InterestRateChartReadService chartReadPlatformService;
+
+ private final CommandPipeline commandPipeline;
@GET
@Path("template")
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
- @Operation(summary = "Retrieve Chart Details Template", description =
"This is a convenience resource. It can be useful when building maintenance
user interface screens for creating a chart. The template data returned
consists of any or all of:\n"
- + "\n" + "Field Defaults\n" + "Allowed Value Lists\n" + "Example
Request:\n" + "\n" + "interestratecharts/template")
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
InterestRateChartsApiResourceSwagger.GetInterestRateChartsTemplateResponse.class)))
- public String template(@Context final UriInfo uriInfo) {
-
this.context.authenticatedUser().validateHasReadPermission(InterestRateChartApiConstants.INTERESTRATE_CHART_RESOURCE_NAME);
-
- InterestRateChartData chartData =
this.chartReadPlatformService.template();
-
- final ApiRequestJsonSerializationSettings settings =
this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- return this.toApiJsonSerializer.serialize(settings, chartData,
INTERESTRATE_CHART_RESPONSE_DATA_PARAMETERS);
+ @Operation(summary = "Retrieve Chart Details Template", description = """
+ This is a convenience resource. It can be useful when building
maintenance user interface screens for creating a chart. The template data
returned consists of any or all of: Field Defaults Allowed Value Lists
+ Example Request: interestratecharts/template
+ """)
+ public InterestRateChartData template(@Context final UriInfo uriInfo) {
+ return chartReadPlatformService.template();
}
@GET
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
- @Operation(summary = "Retrieve all Charts", description = "Retrieve list
of charts associated with a term deposit product(FD or RD).\n"
- + "Example Requests:\n" + "\n" + "interestratecharts?productId=1")
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(array = @ArraySchema(schema = @Schema(implementation =
InterestRateChartsApiResourceSwagger.GetInterestRateChartsResponse.class))))
- public String retrieveAll(@Context final UriInfo uriInfo,
+ @Operation(summary = "Retrieve all Charts", description = """
+ Retrieve list of charts associated with a term deposit product(FD
or RD).
+ Example Requests: interestratecharts?productId=1
+ """)
+ public Collection<InterestRateChartData> retrieveAll(@Context final
UriInfo uriInfo,
@QueryParam("productId") @Parameter(description = "productId")
final Long productId) {
-
this.context.authenticatedUser().validateHasReadPermission(InterestRateChartApiConstants.INTERESTRATE_CHART_RESOURCE_NAME);
-
- Collection<InterestRateChartData> chartDatas =
this.chartReadPlatformService.retrieveAllWithSlabs(productId);
-
- final ApiRequestJsonSerializationSettings settings =
this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- return this.toApiJsonSerializer.serialize(settings, chartDatas,
INTERESTRATE_CHART_RESPONSE_DATA_PARAMETERS);
+ return chartReadPlatformService.retrieveAllWithSlabs(productId);
}
@GET
@Path("{chartId}")
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a Chart", description = "It retrieves the
Interest Rate Chart\n" + "Example Requests:\n" + "\n"
+ "interestratecharts/1")
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
InterestRateChartsApiResourceSwagger.GetInterestRateChartsResponse.class)))
- public String retrieveOne(@PathParam("chartId") @Parameter(description =
"chartId") final Long chartId,
+ public InterestRateChartData retrieveOne(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
@Context final UriInfo uriInfo) {
-
-
this.context.authenticatedUser().validateHasReadPermission(InterestRateChartApiConstants.INTERESTRATE_CHART_RESOURCE_NAME);
-
- InterestRateChartData chartData = null;
+ InterestRateChartData chartData;
final Set<String> associationParameters =
ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
if (!associationParameters.isEmpty() &&
associationParameters.contains(InterestRateChartApiConstants.chartSlabs)) {
- chartData =
this.chartReadPlatformService.retrieveOneWithSlabs(chartId);
+ chartData = chartReadPlatformService.retrieveOneWithSlabs(chartId);
} else {
- chartData = this.chartReadPlatformService.retrieveOne(chartId);
- }
-
- final ApiRequestJsonSerializationSettings settings =
this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- if (settings.isTemplate()) {
- chartData =
this.chartReadPlatformService.retrieveWithTemplate(chartData);
+ chartData = chartReadPlatformService.retrieveOne(chartId);
}
- return this.toApiJsonSerializer.serialize(settings, chartData,
INTERESTRATE_CHART_RESPONSE_DATA_PARAMETERS);
+ return chartData;
}
@POST
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a Chart", description = "Creates a new chart
which can be attached to a term deposit products (FD or RD).")
- @RequestBody(required = true, content = @Content(schema =
@Schema(implementation =
InterestRateChartsApiResourceSwagger.PostInterestRateChartsRequest.class)))
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
InterestRateChartsApiResourceSwagger.PostInterestRateChartsResponse.class)))
- public String create(@Parameter(hidden = true) final String
apiRequestBodyAsJson) {
-
- final CommandWrapper commandRequest = new
CommandWrapperBuilder().createInterestRateChart().withJson(apiRequestBodyAsJson).build();
+ public InterestRateChartCreateResponse create(@Parameter(hidden = true)
final InterestRateChartCreateRequest request) {
Review Comment:
Why would this parameter need to be hidden? The whole point is to describe
the structure of the request body via OpenAPI... how's that supposed to happen
if we hide the source of information?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]