|
18 | 18 | */ |
19 | 19 | package org.apache.fineract.portfolio.interestratechart.api; |
20 | 20 |
|
21 | | -import static org.apache.fineract.portfolio.interestratechart.InterestRateChartSlabApiConstants.INTERESTRATE_CHART_SLAB_RESOURCE_NAME; |
22 | | - |
23 | 21 | import io.swagger.v3.oas.annotations.Operation; |
24 | | -import io.swagger.v3.oas.annotations.Parameter; |
25 | 22 | import io.swagger.v3.oas.annotations.media.Content; |
26 | 23 | import io.swagger.v3.oas.annotations.media.Schema; |
27 | | -import io.swagger.v3.oas.annotations.parameters.RequestBody; |
28 | 24 | import io.swagger.v3.oas.annotations.responses.ApiResponse; |
29 | 25 | import io.swagger.v3.oas.annotations.tags.Tag; |
30 | 26 | import jakarta.ws.rs.Consumes; |
|
35 | 31 | import jakarta.ws.rs.Path; |
36 | 32 | import jakarta.ws.rs.PathParam; |
37 | 33 | import jakarta.ws.rs.Produces; |
38 | | -import jakarta.ws.rs.core.Context; |
39 | 34 | import jakarta.ws.rs.core.MediaType; |
40 | | -import jakarta.ws.rs.core.UriInfo; |
41 | 35 | import java.util.List; |
| 36 | +import java.util.function.Supplier; |
42 | 37 | import lombok.RequiredArgsConstructor; |
43 | | -import org.apache.fineract.commands.domain.CommandWrapper; |
44 | | -import org.apache.fineract.commands.service.CommandWrapperBuilder; |
45 | | -import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; |
46 | | -import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; |
47 | | -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; |
48 | | -import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; |
49 | | -import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; |
50 | | -import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; |
| 38 | +import org.apache.fineract.command.core.CommandPipeline; |
| 39 | +import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsCreateCommand; |
| 40 | +import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsDeleteCommand; |
| 41 | +import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsUpdateCommand; |
51 | 42 | import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabData; |
52 | | -import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartStabRequest; |
53 | | -import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabReadPlatformService; |
| 43 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateRequest; |
| 44 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateResponse; |
| 45 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteRequest; |
| 46 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteResponse; |
| 47 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateRequest; |
| 48 | +import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateResponse; |
| 49 | +import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabsReadService; |
54 | 50 | import org.springframework.stereotype.Component; |
55 | 51 |
|
56 | 52 | @Path("/v1/interestratecharts/{chartId}/chartslabs") |
57 | 53 | @Component |
| 54 | +@Consumes({ MediaType.APPLICATION_JSON }) |
| 55 | +@Produces({ MediaType.APPLICATION_JSON }) |
58 | 56 | @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.") |
59 | 57 | @RequiredArgsConstructor |
60 | 58 | public class InterestRateChartSlabsApiResource { |
61 | 59 |
|
62 | | - private final InterestRateChartSlabReadPlatformService interestRateChartSlabReadPlatformService; |
63 | | - private final PlatformSecurityContext context; |
64 | | - private final DefaultToApiJsonSerializer<InterestRateChartSlabData> toApiJsonSerializer; |
65 | | - private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; |
66 | | - private final ApiRequestParameterHelper apiRequestParameterHelper; |
| 60 | + private final InterestRateChartSlabsReadService interestRateChartSlabsReadService; |
| 61 | + private final CommandPipeline commandPipeline; |
67 | 62 |
|
68 | 63 | @GET |
69 | 64 | @Path("template") |
70 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
71 | | - @Produces({ MediaType.APPLICATION_JSON }) |
72 | | - public InterestRateChartSlabData template(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId) { |
73 | | - return this.interestRateChartSlabReadPlatformService.retrieveTemplate(); |
| 65 | + public InterestRateChartSlabData template(@PathParam("chartId") final Long chartId) { |
| 66 | + return interestRateChartSlabsReadService.retrieveTemplate(); |
74 | 67 | } |
75 | 68 |
|
76 | 69 | @GET |
77 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
78 | | - @Produces({ MediaType.APPLICATION_JSON }) |
79 | 70 | @Operation(summary = "Retrieve all Slabs", description = "Retrieve list of slabs associated with a chart\n" + "\n" |
80 | 71 | + "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs") |
81 | | - public List<InterestRateChartSlabData> retrieveAll(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId) { |
82 | | - |
83 | | - this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME); |
84 | | - return this.interestRateChartSlabReadPlatformService.retrieveAll(chartId); |
| 72 | + public List<InterestRateChartSlabData> retrieveAll(@PathParam("chartId") final Long chartId) { |
| 73 | + return interestRateChartSlabsReadService.retrieveAll(chartId); |
85 | 74 | } |
86 | 75 |
|
87 | 76 | @GET |
88 | 77 | @Path("{chartSlabId}") |
89 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
90 | | - @Produces({ MediaType.APPLICATION_JSON }) |
91 | 78 | @Operation(summary = "Retrieve a Slab", description = "Retrieve a slab associated with an Interest rate chart\n" + "\n" |
92 | 79 | + "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs/1\n") |
93 | | - public InterestRateChartSlabData retrieveOne(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId, |
94 | | - @PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId, @Context final UriInfo uriInfo) { |
95 | | - |
96 | | - this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME); |
97 | | - |
98 | | - InterestRateChartSlabData chartSlab = this.interestRateChartSlabReadPlatformService.retrieveOne(chartId, chartSlabId); |
99 | | - final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); |
100 | | - if (settings.isTemplate()) { |
101 | | - chartSlab = this.interestRateChartSlabReadPlatformService.retrieveWithTemplate(chartSlab); |
102 | | - } |
103 | | - |
104 | | - return chartSlab; |
| 80 | + public InterestRateChartSlabData retrieveOne(@PathParam("chartId") final Long chartId, |
| 81 | + @PathParam("chartSlabId") final Long chartSlabId) { |
| 82 | + return interestRateChartSlabsReadService.retrieveOne(chartId, chartSlabId); |
105 | 83 | } |
106 | 84 |
|
107 | 85 | @POST |
108 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
109 | | - @Produces({ MediaType.APPLICATION_JSON }) |
110 | 86 | @Operation(summary = "Create a Slab", description = "Creates a new interest rate slab for an interest rate chart.\n" |
111 | 87 | + "Mandatory Fields\n" + "periodType, fromPeriod, annualInterestRate\n" + "Optional Fields\n" + "toPeriod and description\n" |
112 | 88 | + "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs") |
113 | | - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = InterestRateChartStabRequest.class))) |
114 | | - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.PostInterestRateChartsChartIdChartSlabsResponse.class))) |
115 | | - public CommandProcessingResult create(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId, |
116 | | - @Parameter(hidden = true) InterestRateChartStabRequest interestRateChartStabRequest) { |
117 | | - |
118 | | - final CommandWrapper commandRequest = new CommandWrapperBuilder().createInterestRateChartSlab(chartId) |
119 | | - .withJson(toApiJsonSerializer.serialize(interestRateChartStabRequest)).build(); |
120 | | - |
121 | | - return this.commandsSourceWritePlatformService.logCommandSource(commandRequest); |
| 89 | + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsCreateResponse.class))) |
| 90 | + public InterestRateChartSlabsCreateResponse create(@PathParam("chartId") final Long chartId, |
| 91 | + final InterestRateChartSlabsCreateRequest request) { |
| 92 | + request.setChartId(chartId); |
| 93 | + final var command = new InterestRateChartSlabsCreateCommand(); |
| 94 | + command.setPayload(request); |
| 95 | + final Supplier<InterestRateChartSlabsCreateResponse> responseSupplier = commandPipeline.send(command); |
| 96 | + return responseSupplier.get(); |
122 | 97 | } |
123 | 98 |
|
124 | 99 | @PUT |
125 | 100 | @Path("{chartSlabId}") |
126 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
127 | | - @Produces({ MediaType.APPLICATION_JSON }) |
128 | 101 | @Operation(summary = "Update a Slab", description = "It updates the Slab from chart") |
129 | | - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = InterestRateChartStabRequest.class))) |
130 | | - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.PutInterestRateChartsChartIdChartSlabsChartSlabIdResponse.class))) |
131 | | - public CommandProcessingResult update(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId, |
132 | | - @PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId, |
133 | | - @Parameter(hidden = true) InterestRateChartStabRequest request) { |
| 102 | + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsUpdateResponse.class))) |
| 103 | + public InterestRateChartSlabsUpdateResponse update(@PathParam("chartId") final Long chartId, |
| 104 | + @PathParam("chartSlabId") final Long chartSlabId, final InterestRateChartSlabsUpdateRequest request) { |
| 105 | + request.setChartId(chartId); |
| 106 | + request.setChartSlabId(chartSlabId); |
| 107 | + |
| 108 | + final var command = new InterestRateChartSlabsUpdateCommand(); |
| 109 | + command.setPayload(request); |
134 | 110 |
|
135 | | - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateInterestRateChartSlab(chartId, chartSlabId) |
136 | | - .withJson(toApiJsonSerializer.serialize(request)).build(); |
| 111 | + final Supplier<InterestRateChartSlabsUpdateResponse> responseSupplier = commandPipeline.send(command); |
137 | 112 |
|
138 | | - return this.commandsSourceWritePlatformService.logCommandSource(commandRequest); |
| 113 | + return responseSupplier.get(); |
139 | 114 | } |
140 | 115 |
|
141 | 116 | @DELETE |
142 | 117 | @Path("{chartSlabId}") |
143 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
144 | | - @Produces({ MediaType.APPLICATION_JSON }) |
145 | 118 | @Operation(summary = "Delete a Slab", description = "Delete a Slab from a chart") |
146 | | - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.DeleteInterestRateChartsChartIdChartSlabsResponse.class))) |
147 | | - public CommandProcessingResult delete(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId, |
148 | | - @PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId) { |
149 | | - final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteInterestRateChartSlab(chartId, chartSlabId).build(); |
150 | | - return this.commandsSourceWritePlatformService.logCommandSource(commandRequest); |
| 119 | + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsDeleteResponse.class))) |
| 120 | + public InterestRateChartSlabsDeleteResponse delete(@PathParam("chartId") final Long chartId, |
| 121 | + @PathParam("chartSlabId") final Long chartSlabId) { |
| 122 | + final var command = new InterestRateChartSlabsDeleteCommand(); |
| 123 | + command.setPayload(InterestRateChartSlabsDeleteRequest.builder().chartId(chartId).chartSlabId(chartSlabId).build()); |
| 124 | + final Supplier<InterestRateChartSlabsDeleteResponse> responseSupplier = commandPipeline.send(command); |
| 125 | + return responseSupplier.get(); |
151 | 126 | } |
152 | 127 | } |
0 commit comments