|
23 | 23 | import io.swagger.v3.oas.annotations.media.Content;
|
24 | 24 | import io.swagger.v3.oas.annotations.media.Schema;
|
25 | 25 | import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
26 |
| -import io.swagger.v3.oas.annotations.responses.ApiResponse; |
27 |
| -import io.swagger.v3.oas.annotations.responses.ApiResponses; |
28 | 26 | import io.swagger.v3.oas.annotations.tags.Tag;
|
| 27 | +import jakarta.validation.Valid; |
29 | 28 | import jakarta.ws.rs.Consumes;
|
30 | 29 | import jakarta.ws.rs.DELETE;
|
31 | 30 | import jakarta.ws.rs.GET;
|
|
37 | 36 | import jakarta.ws.rs.QueryParam;
|
38 | 37 | import jakarta.ws.rs.core.MediaType;
|
39 | 38 | import java.util.List;
|
| 39 | +import java.util.UUID; |
| 40 | +import java.util.function.Supplier; |
40 | 41 | import lombok.RequiredArgsConstructor;
|
41 |
| -import org.apache.fineract.commands.domain.CommandWrapper; |
42 |
| -import org.apache.fineract.commands.service.CommandWrapperBuilder; |
43 |
| -import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; |
44 |
| -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; |
45 |
| -import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; |
| 42 | +import org.apache.fineract.command.core.CommandPipeline; |
| 43 | +import org.apache.fineract.infrastructure.core.service.DateUtils; |
46 | 44 | import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
47 |
| -import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData; |
48 |
| -import org.apache.fineract.portfolio.paymenttype.data.request.PaymentTypeRequest; |
| 45 | +import org.apache.fineract.portfolio.paymenttype.command.CreatePaymentTypeCommand; |
| 46 | +import org.apache.fineract.portfolio.paymenttype.command.DeletePaymentTypeCommand; |
| 47 | +import org.apache.fineract.portfolio.paymenttype.command.UpdatePaymentTypeCommand; |
| 48 | +import org.apache.fineract.portfolio.paymenttype.component.PaymentTypeResponseMapperComponent; |
| 49 | +import org.apache.fineract.portfolio.paymenttype.data.CreatePaymentTypeRequest; |
| 50 | +import org.apache.fineract.portfolio.paymenttype.data.DeletePaymentTypeRequest; |
| 51 | +import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeResponse; |
| 52 | +import org.apache.fineract.portfolio.paymenttype.data.UpdatePaymentTypeRequest; |
49 | 53 | import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper;
|
50 |
| -import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadPlatformService; |
51 | 54 | import org.springframework.stereotype.Component;
|
52 | 55 |
|
53 | 56 | @Path("/v1/paymenttypes")
|
|
57 | 60 | public class PaymentTypeApiResource {
|
58 | 61 |
|
59 | 62 | private final PlatformSecurityContext securityContext;
|
60 |
| - private final DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer; |
61 |
| - private final PaymentTypeReadPlatformService readPlatformService; |
62 |
| - private final PortfolioCommandSourceWritePlatformService commandWritePlatformService; |
63 |
| - private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper; |
| 63 | + private final PaymentTypeResponseMapperComponent paymentTypeResponseMapperComponent; |
| 64 | + private final CommandPipeline commandPipeline; |
| 65 | + private final PaymentTypeRepositoryWrapper paymentTypeRepository; |
64 | 66 |
|
65 | 67 | @GET
|
66 | 68 | @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
|
67 | 69 | @Produces(MediaType.APPLICATION_JSON)
|
68 | 70 | @Operation(summary = "Retrieve all Payment Types", description = "Retrieve list of payment types")
|
69 |
| - public List<PaymentTypeData> getAllPaymentTypes( |
| 71 | + public List<PaymentTypeResponse> getAllPaymentTypes( |
70 | 72 | @QueryParam("onlyWithCode") @Parameter(description = "onlyWithCode") final boolean onlyWithCode) {
|
71 | 73 | securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
|
72 |
| - return onlyWithCode ? readPlatformService.retrieveAllPaymentTypesWithCode() : readPlatformService.retrieveAllPaymentTypes(); |
| 74 | + return onlyWithCode ? paymentTypeResponseMapperComponent.retrieveAllPaymentTypesWithCode() |
| 75 | + : paymentTypeResponseMapperComponent.retrieveAllPaymentTypes(); |
73 | 76 | }
|
74 | 77 |
|
75 | 78 | @GET
|
76 | 79 | @Path("{paymentTypeId}")
|
77 | 80 | @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
|
78 | 81 | @Produces(MediaType.APPLICATION_JSON)
|
79 | 82 | @Operation(summary = "Retrieve a Payment Type", description = "Retrieves a payment type")
|
80 |
| - public PaymentTypeData retrieveOnePaymentType( |
| 83 | + public PaymentTypeResponse retrieveOnePaymentType( |
81 | 84 | @PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
|
82 | 85 | securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
|
83 |
| - paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId); |
84 |
| - return readPlatformService.retrieveOne(paymentTypeId); |
| 86 | + paymentTypeRepository.findOneWithNotFoundDetection(paymentTypeId); |
| 87 | + return paymentTypeResponseMapperComponent.retrieveOne(paymentTypeId); |
85 | 88 | }
|
86 | 89 |
|
87 | 90 | @POST
|
88 | 91 | @Consumes({ MediaType.APPLICATION_JSON })
|
89 | 92 | @Produces({ MediaType.APPLICATION_JSON })
|
90 | 93 | @Operation(summary = "Create a Payment Type", description = "Creates a new Payment type\n\n" + "Mandatory Fields: name\n\n"
|
91 | 94 | + "Optional Fields: Description, isCashPayment,Position")
|
92 |
| - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeRequest.class))) |
93 |
| - @ApiResponses({ |
94 |
| - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PostPaymentTypesResponse.class))) }) |
95 |
| - public CommandProcessingResult createPaymentType(@Parameter(hidden = true) PaymentTypeRequest paymentTypeRequest) { |
| 95 | + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = CreatePaymentTypeRequest.class))) |
| 96 | + public PaymentTypeResponse createPaymentType(@Parameter(hidden = true) @Valid CreatePaymentTypeRequest paymentTypeRequest) { |
| 97 | + var commandPaymentType = new CreatePaymentTypeCommand(); |
| 98 | + commandPaymentType.setId(UUID.randomUUID()); |
| 99 | + commandPaymentType.setCreatedAt(DateUtils.getAuditOffsetDateTime()); |
| 100 | + commandPaymentType.setPayload(paymentTypeRequest); |
96 | 101 |
|
97 |
| - final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaymentType() |
98 |
| - .withJson(jsonSerializer.serialize(paymentTypeRequest)).build(); |
| 102 | + Supplier<PaymentTypeResponse> result = commandPipeline.send(commandPaymentType); |
99 | 103 |
|
100 |
| - CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest); |
101 |
| - return result; |
| 104 | + return result.get(); |
102 | 105 | }
|
103 | 106 |
|
104 | 107 | @PUT
|
105 | 108 | @Path("{paymentTypeId}")
|
106 | 109 | @Consumes({ MediaType.APPLICATION_JSON })
|
107 | 110 | @Produces({ MediaType.APPLICATION_JSON })
|
108 | 111 | @Operation(summary = "Update a Payment Type", description = "Updates a Payment Type")
|
109 |
| - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdRequest.class))) |
110 |
| - @ApiResponses({ |
111 |
| - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdResponse.class))) }) |
112 |
| - public CommandProcessingResult updatePaymentType( |
| 112 | + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = UpdatePaymentTypeRequest.class))) |
| 113 | + public PaymentTypeResponse updatePaymentType( |
113 | 114 | @PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId,
|
114 |
| - @Parameter(hidden = true) final String apiRequestBodyAsJson) { |
| 115 | + @Parameter(hidden = true) @Valid UpdatePaymentTypeRequest paymentTypeRequest) { |
115 | 116 |
|
116 |
| - final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePaymentType(paymentTypeId).withJson(apiRequestBodyAsJson) |
117 |
| - .build(); |
| 117 | + var commandPaymentType = new UpdatePaymentTypeCommand(); |
| 118 | + commandPaymentType.setId(UUID.randomUUID()); |
| 119 | + commandPaymentType.setCreatedAt(DateUtils.getAuditOffsetDateTime()); |
| 120 | + commandPaymentType.setPayload(paymentTypeRequest.setId(paymentTypeId)); |
118 | 121 |
|
119 |
| - final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest); |
120 |
| - return result; |
| 122 | + Supplier<PaymentTypeResponse> result = commandPipeline.send(commandPaymentType); |
| 123 | + |
| 124 | + return result.get(); |
121 | 125 | }
|
122 | 126 |
|
123 | 127 | @DELETE
|
124 | 128 | @Path("{paymentTypeId}")
|
125 | 129 | @Consumes({ MediaType.APPLICATION_JSON })
|
126 | 130 | @Produces({ MediaType.APPLICATION_JSON })
|
127 | 131 | @Operation(summary = "Delete a Payment Type", description = "Deletes payment type")
|
128 |
| - @ApiResponses({ |
129 |
| - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.DeletePaymentTypesPaymentTypeIdResponse.class))) }) |
130 |
| - public CommandProcessingResult deleteCode( |
131 |
| - @PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) { |
132 |
| - |
133 |
| - final CommandWrapper commandRequest = new CommandWrapperBuilder().deletePaymentType(paymentTypeId).build(); |
| 132 | + public PaymentTypeResponse deleteCode(@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) { |
| 133 | + var commandPaymentType = new DeletePaymentTypeCommand(); |
| 134 | + commandPaymentType.setId(UUID.randomUUID()); |
| 135 | + commandPaymentType.setCreatedAt(DateUtils.getAuditOffsetDateTime()); |
| 136 | + commandPaymentType.setPayload(new DeletePaymentTypeRequest(paymentTypeId)); |
134 | 137 |
|
135 |
| - final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest); |
| 138 | + final Supplier<PaymentTypeResponse> result = commandPipeline.send(commandPaymentType); |
136 | 139 |
|
137 |
| - return result; |
| 140 | + return result.get(); |
138 | 141 | }
|
139 | 142 |
|
140 | 143 | }
|
0 commit comments