FINERACT-2169: Financial activity account api refactor;

This commit is contained in:
viktorpavlenko
2025-03-05 14:50:18 +00:00
committed by Adam Saghy
parent 1921606ffc
commit 429374e530
2 changed files with 51 additions and 47 deletions
@@ -40,6 +40,7 @@ import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.financialactivityaccount.data.FinancialActivityAccountData;
import org.apache.fineract.accounting.financialactivityaccount.data.request.FinancialActivityAccRequest;
import org.apache.fineract.accounting.financialactivityaccount.service.FinancialActivityAccountReadPlatformService;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
@@ -77,16 +78,9 @@ public class FinancialActivityAccountsApiResource {
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
FinancialActivityAccountData financialActivityAccountData = this.financialActivityAccountReadPlatformService
.getFinancialActivityAccountTemplate();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, financialActivityAccountData,
FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS);
public FinancialActivityAccountData retrieveTemplate() {
context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
return financialActivityAccountReadPlatformService.getFinancialActivityAccountTemplate();
}
@GET
@@ -96,14 +90,9 @@ public class FinancialActivityAccountsApiResource {
Example Requests:
financialactivityaccounts""")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.GetFinancialActivityAccountsResponse.class))))
public String retrieveAll(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
final List<FinancialActivityAccountData> financialActivityAccounts = this.financialActivityAccountReadPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, financialActivityAccounts,
FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS);
public List<FinancialActivityAccountData> retrieveAll() {
context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
return financialActivityAccountReadPlatformService.retrieveAll();
}
@GET
@@ -114,20 +103,17 @@ public class FinancialActivityAccountsApiResource {
Example Requests:
financialactivityaccounts/1""")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.GetFinancialActivityAccountsResponse.class)))
public String retreive(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId,
public FinancialActivityAccountData retreive(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
FinancialActivityAccountData financialActivityAccountData = this.financialActivityAccountReadPlatformService.retrieve(mappingId);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
FinancialActivityAccountData financialActivityAccountData = financialActivityAccountReadPlatformService.retrieve(mappingId);
if (settings.isTemplate()) {
financialActivityAccountData = this.financialActivityAccountReadPlatformService
.addTemplateDetails(financialActivityAccountData);
financialActivityAccountData = financialActivityAccountReadPlatformService.addTemplateDetails(financialActivityAccountData);
}
return this.apiJsonSerializerService.serialize(settings, financialActivityAccountData,
FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS);
return financialActivityAccountData;
}
@POST
@@ -138,14 +124,11 @@ public class FinancialActivityAccountsApiResource {
financialActivityId, glAccountId""")
@RequestBody(content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.PostFinancialActivityAccountsRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.PostFinancialActivityAccountsResponse.class)))
public String createGLAccount(@Parameter(hidden = true) final String jsonRequestBody) {
public CommandProcessingResult createGLAccount(@Parameter(hidden = true) FinancialActivityAccRequest activityAccRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createOfficeToGLAccountMapping()
.withJson(apiJsonSerializerService.serialize(activityAccRequest)).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().createOfficeToGLAccountMapping().withJson(jsonRequestBody)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.apiJsonSerializerService.serialize(result);
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
@PUT
@@ -155,15 +138,12 @@ public class FinancialActivityAccountsApiResource {
@Operation(summary = "Update a Financial Activity to Account Mapping", description = "the API updates the Ledger account linked to a Financial Activity")
@RequestBody(content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.PostFinancialActivityAccountsRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.PutFinancialActivityAccountsResponse.class)))
public String updateGLAccount(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId,
@Parameter(hidden = true) final String jsonRequestBody) {
public CommandProcessingResult updateGLAccount(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId,
@Parameter(hidden = true) FinancialActivityAccRequest activityAccRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateOfficeToGLAccountMapping(mappingId)
.withJson(jsonRequestBody).build();
.withJson(apiJsonSerializerService.serialize(activityAccRequest)).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.apiJsonSerializerService.serialize(result);
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
@DELETE
@@ -172,12 +152,8 @@ public class FinancialActivityAccountsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a Financial Activity to Account Mapping")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FinancialActivityAccountsApiResourceSwagger.DeleteFinancialActivityAccountsResponse.class)))
public String deleteGLAccount(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId) {
public CommandProcessingResult deleteGLAccount(@PathParam("mappingId") @Parameter(description = "mappingId") final Long mappingId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteOfficeToGLAccountMapping(mappingId).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.apiJsonSerializerService.serialize(result);
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.accounting.financialactivityaccount.data.request;
import java.io.Serial;
import java.io.Serializable;
public record FinancialActivityAccRequest(Long financialActivityId, Long glAccountId) implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}