vidakovic commented on code in PR #5613:
URL: https://github.com/apache/fineract/pull/5613#discussion_r2927243043
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/api/InterestRateChartSlabsApiResource.java:
##########
@@ -35,118 +29,92 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.UriInfo;
import java.util.List;
+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.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.command.core.CommandPipeline;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsCreateCommand;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsDeleteCommand;
+import
org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsUpdateCommand;
import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabData;
-import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartStabRequest;
-import
org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabReadPlatformService;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateResponse;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteResponse;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateRequest;
+import
org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateResponse;
+import
org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabsReadService;
import org.springframework.stereotype.Component;
@Path("/v1/interestratecharts/{chartId}/chartslabs")
@Component
+@Consumes({ MediaType.APPLICATION_JSON })
+@Produces({ MediaType.APPLICATION_JSON })
@Tag(name = "Interest Rate Slab (A.K.A interest bands)", description = "The
slabs a.k.a interest bands are associated with Interest Rate Chart. These bands
allow to define different interest rates for different deposit term periods.")
@RequiredArgsConstructor
public class InterestRateChartSlabsApiResource {
- private final InterestRateChartSlabReadPlatformService
interestRateChartSlabReadPlatformService;
- private final PlatformSecurityContext context;
- private final DefaultToApiJsonSerializer<InterestRateChartSlabData>
toApiJsonSerializer;
- private final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService;
- private final ApiRequestParameterHelper apiRequestParameterHelper;
+ private final InterestRateChartSlabsReadService
interestRateChartSlabsReadService;
+ private final CommandPipeline commandPipeline;
@GET
@Path("template")
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
public InterestRateChartSlabData template(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId) {
- return
this.interestRateChartSlabReadPlatformService.retrieveTemplate();
+ return interestRateChartSlabsReadService.retrieveTemplate();
}
@GET
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve all Slabs", description = "Retrieve list of
slabs associated with a chart\n" + "\n"
+ "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs")
public List<InterestRateChartSlabData> retrieveAll(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId) {
-
-
this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME);
- return
this.interestRateChartSlabReadPlatformService.retrieveAll(chartId);
+ return interestRateChartSlabsReadService.retrieveAll(chartId);
}
@GET
@Path("{chartSlabId}")
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a Slab", description = "Retrieve a slab
associated with an Interest rate chart\n" + "\n"
+ "Example Requests:\n" + "\n" +
"interestratecharts/1/chartslabs/1\n")
public InterestRateChartSlabData retrieveOne(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
- @PathParam("chartSlabId") @Parameter(description = "chartSlabId")
final Long chartSlabId, @Context final UriInfo uriInfo) {
-
-
this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME);
-
- InterestRateChartSlabData chartSlab =
this.interestRateChartSlabReadPlatformService.retrieveOne(chartId, chartSlabId);
- final ApiRequestJsonSerializationSettings settings =
this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- if (settings.isTemplate()) {
- chartSlab =
this.interestRateChartSlabReadPlatformService.retrieveWithTemplate(chartSlab);
- }
-
- return chartSlab;
+ @PathParam("chartSlabId") @Parameter(description = "chartSlabId")
final Long chartSlabId) {
+ return interestRateChartSlabsReadService.retrieveOne(chartId,
chartSlabId);
}
@POST
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a Slab", description = "Creates a new
interest rate slab for an interest rate chart.\n"
+ "Mandatory Fields\n" + "periodType, fromPeriod,
annualInterestRate\n" + "Optional Fields\n" + "toPeriod and description\n"
+ "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs")
- @RequestBody(required = true, content = @Content(schema =
@Schema(implementation = InterestRateChartStabRequest.class)))
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
InterestRateChartSlabsApiResourceSwagger.PostInterestRateChartsChartIdChartSlabsResponse.class)))
- public CommandProcessingResult create(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
- @Parameter(hidden = true) InterestRateChartStabRequest
interestRateChartStabRequest) {
-
- final CommandWrapper commandRequest = new
CommandWrapperBuilder().createInterestRateChartSlab(chartId)
-
.withJson(toApiJsonSerializer.serialize(interestRateChartStabRequest)).build();
-
- return
this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ public InterestRateChartSlabsCreateResponse create(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
+ @Parameter(hidden = true) final
InterestRateChartSlabsCreateRequest request) {
+ request.setChartId(chartId);
+ final var command = new InterestRateChartSlabsCreateCommand();
+ command.setPayload(request);
+ final Supplier<InterestRateChartSlabsCreateResponse> responseSupplier
= commandPipeline.send(command);
+ return responseSupplier.get();
}
@PUT
@Path("{chartSlabId}")
- @Consumes({ MediaType.APPLICATION_JSON })
- @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a Slab", description = "It updates the Slab
from chart")
- @RequestBody(required = true, content = @Content(schema =
@Schema(implementation = InterestRateChartStabRequest.class)))
- @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
InterestRateChartSlabsApiResourceSwagger.PutInterestRateChartsChartIdChartSlabsChartSlabIdResponse.class)))
- public CommandProcessingResult update(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
+ public InterestRateChartSlabsUpdateResponse update(@PathParam("chartId")
@Parameter(description = "chartId") final Long chartId,
@PathParam("chartSlabId") @Parameter(description = "chartSlabId")
final Long chartSlabId,
- @Parameter(hidden = true) InterestRateChartStabRequest request) {
-
- final CommandWrapper commandRequest = new
CommandWrapperBuilder().updateInterestRateChartSlab(chartId, chartSlabId)
- .withJson(toApiJsonSerializer.serialize(request)).build();
-
- return
this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ @Parameter(hidden = true) final
InterestRateChartSlabsUpdateRequest request) {
+ request.setChartId(chartId);
Review Comment:
A general suggestion about aligning code. Technically not an error... but
keep in mind that - as you can see - there is more reading than coding involved
when coding. That being said: if things get a bit cramped then this is a
strain on the eyes. So, how about this:
```java
request.setChartId(chartId);
request.setChartSlabId(chartSlabId);
final var command = new InterestRateChartSlabsUpdateCommand();
command.setPayload(request);
final Supplier<InterestRateChartSlabsUpdateResponse> responseSupplier =
commandPipeline.send(command);
return responseSupplier.get();
```
The other variant obviously is correct and compiles... but I think that
suggested formatting makes things easier to scan and understand for a human
being.
--
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]