2626import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
2727import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
2828import io .swagger .v3 .oas .annotations .tags .Tag ;
29+ import jakarta .ws .rs .BeanParam ;
2930import jakarta .ws .rs .Consumes ;
3031import jakarta .ws .rs .GET ;
3132import jakarta .ws .rs .POST ;
3233import jakarta .ws .rs .Path ;
3334import jakarta .ws .rs .PathParam ;
3435import jakarta .ws .rs .Produces ;
3536import jakarta .ws .rs .QueryParam ;
36- import jakarta .ws .rs .core .Context ;
3737import jakarta .ws .rs .core .MediaType ;
38- import jakarta .ws .rs .core .UriInfo ;
3938import lombok .RequiredArgsConstructor ;
4039import org .apache .fineract .commands .domain .CommandWrapper ;
4140import org .apache .fineract .commands .service .CommandWrapperBuilder ;
4241import org .apache .fineract .commands .service .PortfolioCommandSourceWritePlatformService ;
43- import org .apache .fineract .infrastructure .core .api .ApiRequestParameterHelper ;
4442import org .apache .fineract .infrastructure .core .data .CommandProcessingResult ;
45- import org .apache .fineract .infrastructure .core .serialization .ApiRequestJsonSerializationSettings ;
4643import org .apache .fineract .infrastructure .core .serialization .DefaultToApiJsonSerializer ;
4744import org .apache .fineract .infrastructure .core .service .Page ;
4845import org .apache .fineract .infrastructure .core .service .SearchParameters ;
4946import org .apache .fineract .infrastructure .security .service .PlatformSecurityContext ;
50- import org .apache .fineract .infrastructure .security .service .SqlValidator ;
5147import org .apache .fineract .portfolio .account .data .AccountTransferData ;
48+ import org .apache .fineract .portfolio .account .data .request .AccountTransSearchParam ;
49+ import org .apache .fineract .portfolio .account .data .request .AccountTransferRequest ;
5250import org .apache .fineract .portfolio .account .service .AccountTransfersReadPlatformService ;
5351import org .springframework .stereotype .Component ;
5452
@@ -61,9 +59,7 @@ public class AccountTransfersApiResource {
6159 private final PlatformSecurityContext context ;
6260 private final DefaultToApiJsonSerializer <AccountTransferData > toApiJsonSerializer ;
6361 private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService ;
64- private final ApiRequestParameterHelper apiRequestParameterHelper ;
6562 private final AccountTransfersReadPlatformService accountTransfersReadPlatformService ;
66- private final SqlValidator sqlValidator ;
6763
6864 @ GET
6965 @ Path ("template" )
@@ -76,38 +72,28 @@ public class AccountTransfersApiResource {
7672 + "accounttransfers/template?fromClientId=1&fromAccountType=2&fromAccountId=1" )
7773 @ ApiResponses ({
7874 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .GetAccountTransfersTemplateResponse .class ))) })
79- public String template (@ QueryParam ("fromOfficeId" ) @ Parameter (description = "fromOfficeId" ) final Long fromOfficeId ,
80- @ QueryParam ("fromClientId" ) @ Parameter (description = "fromClientId" ) final Long fromClientId ,
81- @ QueryParam ("fromAccountId" ) @ Parameter (description = "fromAccountId" ) final Long fromAccountId ,
82- @ QueryParam ("fromAccountType" ) @ Parameter (description = "fromAccountType" ) final Integer fromAccountType ,
83- @ QueryParam ("toOfficeId" ) @ Parameter (description = "toOfficeId" ) final Long toOfficeId ,
84- @ QueryParam ("toClientId" ) @ Parameter (description = "toClientId" ) final Long toClientId ,
85- @ QueryParam ("toAccountId" ) @ Parameter (description = "toAccountId" ) final Long toAccountId ,
86- @ QueryParam ("toAccountType" ) @ Parameter (description = "toAccountType" ) final Integer toAccountType ,
87- @ Context final UriInfo uriInfo ) {
75+ public AccountTransferData template (@ BeanParam AccountTransSearchParam accountTransSearchParam ) {
8876
89- this . context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
77+ context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
9078
91- final AccountTransferData transferData = this . accountTransfersReadPlatformService .retrieveTemplate (fromOfficeId , fromClientId ,
92- fromAccountId , fromAccountType , toOfficeId , toClientId , toAccountId , toAccountType );
93-
94- final ApiRequestJsonSerializationSettings settings = this . apiRequestParameterHelper . process ( uriInfo . getQueryParameters ());
95- return this . toApiJsonSerializer . serialize ( settings , transferData , AccountTransfersApiConstants . RESPONSE_DATA_PARAMETERS );
79+ return accountTransfersReadPlatformService .retrieveTemplate (accountTransSearchParam . getFromAccountId () ,
80+ accountTransSearchParam . getFromClientId (), accountTransSearchParam . getFromAccountId (),
81+ accountTransSearchParam . getFromAccountType (), accountTransSearchParam . getToOfficeId (),
82+ accountTransSearchParam . getToClientId (), accountTransSearchParam . getToAccountId (),
83+ accountTransSearchParam . getToAccountType () );
9684 }
9785
9886 @ POST
9987 @ Consumes ({ MediaType .APPLICATION_JSON })
10088 @ Produces ({ MediaType .APPLICATION_JSON })
10189 @ Operation (summary = "Create new Transfer" , description = "Ability to create new transfer of monetary funds from one account to another." )
102- @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger . PostAccountTransfersRequest .class )))
90+ @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = AccountTransferRequest .class )))
10391 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .PostAccountTransfersResponse .class )))
104- public String create (@ Parameter (hidden = true ) final String apiRequestBodyAsJson ) {
105-
106- final CommandWrapper commandRequest = new CommandWrapperBuilder (). createAccountTransfer (). withJson ( apiRequestBodyAsJson ).build ();
92+ public CommandProcessingResult create (@ Parameter (hidden = true ) AccountTransferRequest accountTransferRequest ) {
93+ final CommandWrapper commandRequest = new CommandWrapperBuilder (). createAccountTransfer ()
94+ . withJson ( toApiJsonSerializer . serialize ( accountTransferRequest ) ).build ();
10795
108- final CommandProcessingResult result = this .commandsSourceWritePlatformService .logCommandSource (commandRequest );
109-
110- return this .toApiJsonSerializer .serialize (result );
96+ return commandsSourceWritePlatformService .logCommandSource (commandRequest );
11197 }
11298
11399 @ GET
@@ -117,26 +103,19 @@ public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson
117103 + "accounttransfers" )
118104 @ ApiResponses ({
119105 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .GetAccountTransfersResponse .class ))) })
120- public String retrieveAll (@ Context final UriInfo uriInfo ,
121- @ QueryParam ("externalId" ) @ Parameter (description = "externalId" ) final String externalId ,
106+ public Page <AccountTransferData > retrieveAll (@ QueryParam ("externalId" ) @ Parameter (description = "externalId" ) final String externalId ,
122107 @ QueryParam ("offset" ) @ Parameter (description = "offset" ) final Integer offset ,
123108 @ QueryParam ("limit" ) @ Parameter (example = "limit" ) final Integer limit ,
124109 @ QueryParam ("orderBy" ) @ Parameter (description = "orderBy" ) final String orderBy ,
125110 @ QueryParam ("sortOrder" ) @ Parameter (description = "sortOrder" ) final String sortOrder ,
126111 @ QueryParam ("accountDetailId" ) @ Parameter (description = "accountDetailId" ) final Long accountDetailId ) {
127112
128- this . context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
113+ context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
129114
130- sqlValidator .validate (orderBy );
131- sqlValidator .validate (sortOrder );
132- sqlValidator .validate (externalId );
133115 final SearchParameters searchParameters = SearchParameters .builder ().limit (limit ).externalId (externalId ).offset (offset )
134116 .orderBy (orderBy ).sortOrder (sortOrder ).build ();
135117
136- final Page <AccountTransferData > transfers = this .accountTransfersReadPlatformService .retrieveAll (searchParameters , accountDetailId );
137-
138- final ApiRequestJsonSerializationSettings settings = this .apiRequestParameterHelper .process (uriInfo .getQueryParameters ());
139- return this .toApiJsonSerializer .serialize (settings , transfers , AccountTransfersApiConstants .RESPONSE_DATA_PARAMETERS );
118+ return accountTransfersReadPlatformService .retrieveAll (searchParameters , accountDetailId );
140119 }
141120
142121 @ GET
@@ -147,15 +126,9 @@ public String retrieveAll(@Context final UriInfo uriInfo,
147126 + "accounttransfers/1" )
148127 @ ApiResponses ({
149128 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .GetAccountTransfersResponse .GetAccountTransfersPageItems .class ))) })
150- public String retrieveOne (@ PathParam ("transferId" ) @ Parameter (description = "transferId" ) final Long transferId ,
151- @ Context final UriInfo uriInfo ) {
152-
153- this .context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
154-
155- final AccountTransferData transfer = this .accountTransfersReadPlatformService .retrieveOne (transferId );
156-
157- final ApiRequestJsonSerializationSettings settings = this .apiRequestParameterHelper .process (uriInfo .getQueryParameters ());
158- return this .toApiJsonSerializer .serialize (settings , transfer , AccountTransfersApiConstants .RESPONSE_DATA_PARAMETERS );
129+ public AccountTransferData retrieveOne (@ PathParam ("transferId" ) @ Parameter (description = "transferId" ) final Long transferId ) {
130+ context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
131+ return accountTransfersReadPlatformService .retrieveOne (transferId );
159132 }
160133
161134 @ GET
@@ -167,39 +140,26 @@ public String retrieveOne(@PathParam("transferId") @Parameter(description = "tra
167140 + "accounttransfers/templateRefundByTransfer?fromAccountId=2&fromAccountType=1& toAccountId=1&toAccountType=2&toClientId=1&toOfficeId=1" )
168141 @ ApiResponses ({
169142 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .GetAccountTransfersTemplateRefundByTransferResponse .class ))) })
170- public String templateRefundByTransfer (@ QueryParam ("fromOfficeId" ) @ Parameter (description = "fromOfficeId" ) final Long fromOfficeId ,
171- @ QueryParam ("fromClientId" ) @ Parameter (description = "fromClientId" ) final Long fromClientId ,
172- @ QueryParam ("fromAccountId" ) @ Parameter (description = "fromAccountId" ) final Long fromAccountId ,
173- @ QueryParam ("fromAccountType" ) @ Parameter (description = "fromAccountType" ) final Integer fromAccountType ,
174- @ QueryParam ("toOfficeId" ) @ Parameter (description = "toOfficeId" ) final Long toOfficeId ,
175- @ QueryParam ("toClientId" ) @ Parameter (description = "toClientId" ) final Long toClientId ,
176- @ QueryParam ("toAccountId" ) @ Parameter (description = "toAccountId" ) final Long toAccountId ,
177- @ QueryParam ("toAccountType" ) @ Parameter (description = "toAccountType" ) final Integer toAccountType ,
178- @ Context final UriInfo uriInfo ) {
179-
180- this .context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
181-
182- final AccountTransferData transferData = this .accountTransfersReadPlatformService .retrieveRefundByTransferTemplate (fromOfficeId ,
183- fromClientId , fromAccountId , fromAccountType , toOfficeId , toClientId , toAccountId , toAccountType );
184-
185- final ApiRequestJsonSerializationSettings settings = this .apiRequestParameterHelper .process (uriInfo .getQueryParameters ());
186- return this .toApiJsonSerializer .serialize (settings , transferData , AccountTransfersApiConstants .RESPONSE_DATA_PARAMETERS );
143+ public AccountTransferData templateRefundByTransfer (@ BeanParam AccountTransSearchParam accountTransSearchParam ) {
144+ context .authenticatedUser ().validateHasReadPermission (AccountTransfersApiConstants .ACCOUNT_TRANSFER_RESOURCE_NAME );
145+ return accountTransfersReadPlatformService .retrieveRefundByTransferTemplate (accountTransSearchParam .getFromAccountId (),
146+ accountTransSearchParam .getFromClientId (), accountTransSearchParam .getFromAccountId (),
147+ accountTransSearchParam .getFromAccountType (), accountTransSearchParam .getToOfficeId (),
148+ accountTransSearchParam .getToClientId (), accountTransSearchParam .getToAccountId (),
149+ accountTransSearchParam .getToAccountType ());
187150 }
188151
189152 @ POST
190153 @ Path ("refundByTransfer" )
191154 @ Consumes ({ MediaType .APPLICATION_JSON })
192155 @ Produces ({ MediaType .APPLICATION_JSON })
193156 @ Operation (summary = "Refund of an Active Loan by Transfer" , description = "Ability to refund an active loan by transferring to a savings account." )
194- @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger . PostAccountTransfersRefundByTransferRequest .class )))
157+ @ RequestBody (required = true , content = @ Content (schema = @ Schema (implementation = AccountTransferRequest .class )))
195158 @ ApiResponses ({
196159 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (schema = @ Schema (implementation = AccountTransfersApiResourceSwagger .PostAccountTransfersRefundByTransferResponse .class ))) })
197- public String templateRefundByTransferPost (@ Parameter (hidden = true ) final String apiRequestBodyAsJson ) {
198-
199- final CommandWrapper commandRequest = new CommandWrapperBuilder ().refundByTransfer ().withJson (apiRequestBodyAsJson ).build ();
200-
201- final CommandProcessingResult result = this .commandsSourceWritePlatformService .logCommandSource (commandRequest );
202-
203- return this .toApiJsonSerializer .serialize (result );
160+ public CommandProcessingResult templateRefundByTransferPost (@ Parameter (hidden = true ) AccountTransferRequest accountTransferRequest ) {
161+ final CommandWrapper commandRequest = new CommandWrapperBuilder ().refundByTransfer ()
162+ .withJson (toApiJsonSerializer .serialize (accountTransferRequest )).build ();
163+ return commandsSourceWritePlatformService .logCommandSource (commandRequest );
204164 }
205165}
0 commit comments