1919package org .apache .fineract .portfolio .paymenttype .api ;
2020
2121import io .swagger .v3 .oas .annotations .Operation ;
22- import io .swagger .v3 .oas .annotations .Parameter ;
23- import io .swagger .v3 .oas .annotations .media .Content ;
24- import io .swagger .v3 .oas .annotations .media .Schema ;
25- import io .swagger .v3 .oas .annotations .parameters .RequestBody ;
26- import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
2722import io .swagger .v3 .oas .annotations .tags .Tag ;
2823import jakarta .ws .rs .Consumes ;
2924import jakarta .ws .rs .DELETE ;
3631import jakarta .ws .rs .QueryParam ;
3732import jakarta .ws .rs .core .MediaType ;
3833import java .util .List ;
34+ import java .util .function .Supplier ;
3935import lombok .RequiredArgsConstructor ;
40- import org .apache .fineract .commands .domain .CommandWrapper ;
41- import org .apache .fineract .commands .service .CommandWrapperBuilder ;
42- import org .apache .fineract .commands .service .PortfolioCommandSourceWritePlatformService ;
43- import org .apache .fineract .infrastructure .core .data .CommandProcessingResult ;
36+ import org .apache .fineract .command .core .CommandPipeline ;
4437import org .apache .fineract .infrastructure .core .serialization .DefaultToApiJsonSerializer ;
45- import org .apache .fineract .infrastructure .security .service .PlatformSecurityContext ;
38+ import org .apache .fineract .portfolio .paymenttype .command .PaymentTypeCreateCommand ;
39+ import org .apache .fineract .portfolio .paymenttype .command .PaymentTypeDeleteCommand ;
40+ import org .apache .fineract .portfolio .paymenttype .command .PaymentTypeUpdateCommand ;
41+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeCreateRequest ;
42+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeCreateResponse ;
4643import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeData ;
47- import org .apache .fineract .portfolio .paymenttype .data .request .PaymentTypeRequest ;
48- import org .apache .fineract .portfolio .paymenttype .domain .PaymentTypeRepositoryWrapper ;
49- import org .apache .fineract .portfolio .paymenttype .service .PaymentTypeReadPlatformService ;
44+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeDeleteRequest ;
45+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeDeleteResponse ;
46+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeUpdateRequest ;
47+ import org .apache .fineract .portfolio .paymenttype .data .PaymentTypeUpdateResponse ;
48+ import org .apache .fineract .portfolio .paymenttype .service .PaymentTypeReadService ;
5049import org .springframework .stereotype .Component ;
5150
5251@ Path ("/v1/paymenttypes" )
5554@ RequiredArgsConstructor
5655public class PaymentTypeApiResource {
5756
58- private final PlatformSecurityContext securityContext ;
57+ private final PaymentTypeReadService readPlatformService ;
58+ private final CommandPipeline commandPipeline ;
5959 private final DefaultToApiJsonSerializer <PaymentTypeData > jsonSerializer ;
60- private final PaymentTypeReadPlatformService readPlatformService ;
61- private final PortfolioCommandSourceWritePlatformService commandWritePlatformService ;
62- private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper ;
6360
6461 @ GET
6562 @ Consumes ({ MediaType .TEXT_HTML , MediaType .APPLICATION_JSON })
6663 @ Produces (MediaType .APPLICATION_JSON )
6764 @ Operation (summary = "Retrieve all Payment Types" , description = "Retrieve list of payment types" )
68- public List <PaymentTypeData > getAllPaymentTypes (
69- @ QueryParam ("onlyWithCode" ) @ Parameter (description = "onlyWithCode" ) final boolean onlyWithCode ) {
70- securityContext .authenticatedUser ().validateHasReadPermission (PaymentTypeApiResourceConstants .ENTITY_NAME );
65+ public List <PaymentTypeData > getAllPaymentTypes (@ QueryParam ("onlyWithCode" ) final boolean onlyWithCode ) {
7166 return onlyWithCode ? readPlatformService .retrieveAllPaymentTypesWithCode () : readPlatformService .retrieveAllPaymentTypes ();
7267 }
7368
@@ -76,61 +71,58 @@ public List<PaymentTypeData> getAllPaymentTypes(
7671 @ Consumes ({ MediaType .TEXT_HTML , MediaType .APPLICATION_JSON })
7772 @ Produces (MediaType .APPLICATION_JSON )
7873 @ Operation (summary = "Retrieve a Payment Type" , description = "Retrieves a payment type" )
79- public PaymentTypeData retrieveOnePaymentType (
80- @ PathParam ("paymentTypeId" ) @ Parameter (description = "paymentTypeId" ) final Long paymentTypeId ) {
81- securityContext .authenticatedUser ().validateHasReadPermission (PaymentTypeApiResourceConstants .ENTITY_NAME );
82- paymentTypeRepositoryWrapper .findOneWithNotFoundDetection (paymentTypeId );
74+ public PaymentTypeData retrieveOnePaymentType (@ PathParam ("paymentTypeId" ) final Long paymentTypeId ) {
8375 return readPlatformService .retrieveOne (paymentTypeId );
8476 }
8577
8678 @ POST
8779 @ Consumes ({ MediaType .APPLICATION_JSON })
8880 @ Produces ({ MediaType .APPLICATION_JSON })
89- @ Operation (summary = "Create a Payment Type" , description = "Creates a new Payment type\n \n " + "Mandatory Fields: name\n \n "
90- + "Optional Fields: Description, isCashPayment,Position" )
91- @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = PaymentTypeRequest .class )))
92- @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = PaymentTypeApiResourceSwagger .PostPaymentTypesResponse .class )))
93- public CommandProcessingResult createPaymentType (@ Parameter (hidden = true ) PaymentTypeRequest paymentTypeRequest ) {
81+ @ Operation (summary = "Create a Payment Type" , description = "Creates a new Payment type" )
82+ public PaymentTypeCreateResponse createPaymentType (PaymentTypeCreateRequest request ) {
83+ final var command = new PaymentTypeCreateCommand ();
9484
95- final CommandWrapper commandRequest = new CommandWrapperBuilder ().createPaymentType ()
96- .withJson (jsonSerializer .serialize (paymentTypeRequest )).build ();
85+ command .setPayload (request );
9786
98- CommandProcessingResult result = commandWritePlatformService .logCommandSource (commandRequest );
99- return result ;
87+ final Supplier <PaymentTypeCreateResponse > response = commandPipeline .send (command );
88+
89+ return response .get ();
10090 }
10191
10292 @ PUT
10393 @ Path ("{paymentTypeId}" )
10494 @ Consumes ({ MediaType .APPLICATION_JSON })
10595 @ Produces ({ MediaType .APPLICATION_JSON })
10696 @ Operation (summary = "Update a Payment Type" , description = "Updates a Payment Type" )
107- @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = PaymentTypeApiResourceSwagger .PutPaymentTypesPaymentTypeIdRequest .class )))
108- @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = PaymentTypeApiResourceSwagger .PutPaymentTypesPaymentTypeIdResponse .class )))
109- public CommandProcessingResult updatePaymentType (
110- @ PathParam ("paymentTypeId" ) @ Parameter (description = "paymentTypeId" ) final Long paymentTypeId ,
111- @ Parameter (hidden = true ) final String apiRequestBodyAsJson ) {
97+ public PaymentTypeUpdateResponse updatePaymentType (@ PathParam ("paymentTypeId" ) final Long paymentTypeId ,
98+ final PaymentTypeUpdateRequest request ) {
99+
100+ request .setId (paymentTypeId );
101+
102+ final var command = new PaymentTypeUpdateCommand ();
103+
104+ command .setPayload (request );
112105
113- final CommandWrapper commandRequest = new CommandWrapperBuilder ().updatePaymentType (paymentTypeId ).withJson (apiRequestBodyAsJson )
114- .build ();
106+ final Supplier <PaymentTypeUpdateResponse > response = commandPipeline .send (command );
115107
116- final CommandProcessingResult result = commandWritePlatformService .logCommandSource (commandRequest );
117- return result ;
108+ return response .get ();
118109 }
119110
120111 @ DELETE
121112 @ Path ("{paymentTypeId}" )
122113 @ Consumes ({ MediaType .APPLICATION_JSON })
123114 @ Produces ({ MediaType .APPLICATION_JSON })
124115 @ Operation (summary = "Delete a Payment Type" , description = "Deletes payment type" )
125- @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = PaymentTypeApiResourceSwagger .DeletePaymentTypesPaymentTypeIdResponse .class )))
126- public CommandProcessingResult deleteCode (
127- @ PathParam ("paymentTypeId" ) @ Parameter (description = "paymentTypeId" ) final Long paymentTypeId ) {
116+ public PaymentTypeDeleteResponse deleteCode (@ PathParam ("paymentTypeId" ) final Long paymentTypeId ) {
128117
129- final CommandWrapper commandRequest = new CommandWrapperBuilder ().deletePaymentType (paymentTypeId ).build ();
118+ final var request = PaymentTypeDeleteRequest . builder ().id (paymentTypeId ).build ();
130119
131- final CommandProcessingResult result = commandWritePlatformService . logCommandSource ( commandRequest );
120+ final var command = new PaymentTypeDeleteCommand ( );
132121
133- return result ;
134- }
122+ command .setPayload (request );
123+
124+ final Supplier <PaymentTypeDeleteResponse > response = commandPipeline .send (command );
135125
126+ return response .get ();
127+ }
136128}
0 commit comments