FINERACT-2169: Glclosure account api refactor;
This commit is contained in:
committed by
Adam Saghy
parent
d98f5b0d0e
commit
a41891e776
+22
-41
@@ -39,12 +39,10 @@ import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.closure.data.GLClosureData;
|
||||
import org.apache.fineract.accounting.closure.data.request.GLClosureRequest;
|
||||
import org.apache.fineract.accounting.closure.service.GLClosureReadPlatformService;
|
||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||
@@ -66,10 +64,6 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor
|
||||
public class GLClosuresApiResource {
|
||||
|
||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(
|
||||
Arrays.asList("id", "officeId", "officeName", "closingDate", "deleted", "createdDate", "lastUpdatedDate", "createdByUserId",
|
||||
"createdByUsername", "lastUpdatedByUserId", "lastUpdatedByUsername"));
|
||||
|
||||
private static final String RESOURCE_NAME_FOR_PERMISSION = "GLCLOSURE";
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
@@ -85,14 +79,10 @@ public class GLClosuresApiResource {
|
||||
@Operation(summary = "List Accounting closures", description = "Example Requests:\n" + "\n" + "glclosures")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = GLClosuresApiResourceSwagger.GetGlClosureResponse.class)))) })
|
||||
public String retrieveAllClosures(@Context final UriInfo uriInfo,
|
||||
@QueryParam("officeId") @Parameter(name = "officeId") final Long officeId) {
|
||||
public List<GLClosureData> retrieveAllClosures(@QueryParam("officeId") @Parameter(name = "officeId") final Long officeId) {
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
|
||||
final List<GLClosureData> glClosureDatas = this.glClosureReadPlatformService.retrieveAllGLClosures(officeId);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.apiJsonSerializerService.serialize(settings, glClosureDatas, RESPONSE_DATA_PARAMETERS);
|
||||
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
|
||||
return glClosureReadPlatformService.retrieveAllGLClosures(officeId);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -103,19 +93,17 @@ public class GLClosuresApiResource {
|
||||
+ "/glclosures/1?fields=officeName,closingDate")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.GetGlClosureResponse.class))) })
|
||||
public String retreiveClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
|
||||
public GLClosureData retreiveClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
final GLClosureData glClosureData = this.glClosureReadPlatformService.retrieveGLClosureById(glClosureId);
|
||||
final GLClosureData glClosureData = glClosureReadPlatformService.retrieveGLClosureById(glClosureId);
|
||||
if (settings.isTemplate()) {
|
||||
glClosureData.setAllowedOffices(this.officeReadPlatformService.retrieveAllOfficesForDropdown());
|
||||
glClosureData.setAllowedOffices(officeReadPlatformService.retrieveAllOfficesForDropdown());
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serialize(settings, glClosureData, RESPONSE_DATA_PARAMETERS);
|
||||
return glClosureData;
|
||||
}
|
||||
|
||||
// NOTE: proposal slight changes @Aleks
|
||||
@@ -126,13 +114,11 @@ public class GLClosuresApiResource {
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PostGlClosuresRequest.class, description = "Request Body")))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PostGlClosuresResponse.class))) })
|
||||
public String createGLClosure(@Parameter(hidden = true) final String jsonRequestBody) {
|
||||
public CommandProcessingResult createGLClosure(@Parameter(hidden = true) GLClosureRequest glClosureRequest) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createGLClosure()
|
||||
.withJson(apiJsonSerializerService.serialize(glClosureRequest)).build();
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createGLClosure().withJson(jsonRequestBody).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -143,13 +129,11 @@ public class GLClosuresApiResource {
|
||||
@RequestBody(content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresRequest.class, required = true)))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresResponse.class))) })
|
||||
public String updateGLClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
|
||||
@Parameter(hidden = true) final String jsonRequestBody) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateGLClosure(glClosureId).withJson(jsonRequestBody).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
public CommandProcessingResult updateGLClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
|
||||
@Parameter(hidden = true) GLClosureRequest glClosureRequest) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateGLClosure(glClosureId)
|
||||
.withJson(apiJsonSerializerService.serialize(glClosureRequest)).build();
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@@ -159,12 +143,9 @@ public class GLClosuresApiResource {
|
||||
@Operation(summary = "Delete an accounting closure", description = "Note: Only the latest accounting closure associated with a branch may be deleted.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.DeleteGlClosuresResponse.class))) })
|
||||
public String deleteGLClosure(@PathParam("glClosureId") @Parameter(description = "glclosureId") final Long glClosureId) {
|
||||
|
||||
public CommandProcessingResult deleteGLClosure(
|
||||
@PathParam("glClosureId") @Parameter(description = "glclosureId") final Long glClosureId) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteGLClosure(glClosureId).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -21,8 +21,6 @@ package org.apache.fineract.accounting.closure.command;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.closure.api.GLClosureJsonInputParams;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
|
||||
@@ -31,14 +29,7 @@ import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidati
|
||||
/**
|
||||
* Immutable command for adding an accounting closure
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class GLClosureCommand {
|
||||
|
||||
private final Long id;
|
||||
private final Long officeId;
|
||||
private final LocalDate closingDate;
|
||||
private final String comments;
|
||||
public record GLClosureCommand(Long id, Long officeId, LocalDate closingDate, String comments) {
|
||||
|
||||
public void validateForCreate() {
|
||||
|
||||
|
||||
+6
-1
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.fineract.accounting.closure.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -30,7 +32,10 @@ import org.apache.fineract.organisation.office.data.OfficeData;
|
||||
* Note: no getter/setters required as google-gson will produce json from fields of object.
|
||||
*/
|
||||
@Data
|
||||
public class GLClosureData {
|
||||
public class GLClosureData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final Long officeId;
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.closure.data.request;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
public record GLClosureRequest(Long id, Long officeId, String closingDate, String comments, String dateFormat,
|
||||
String locale) implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user