FINERACT-2169: Apply dto for payment type api and upgrade swagger doc;

This commit is contained in:
viktorpavlenko
2025-03-14 18:17:41 +00:00
committed by Adam Saghy
parent 707fe3d0e5
commit e1aa632ccc
20 changed files with 108 additions and 138 deletions
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.paymenttype.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
@@ -36,20 +35,17 @@ import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
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.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
import org.apache.fineract.portfolio.paymenttype.data.request.PaymentTypeRequest;
import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper;
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadPlatformService;
import org.springframework.stereotype.Component;
@@ -64,26 +60,16 @@ public class PaymentTypeApiResource {
private final DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer;
private final PaymentTypeReadPlatformService readPlatformService;
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper;
@GET
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Retrieve all Payment Types", description = "Retrieve list of payment types")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.GetPaymentTypesResponse.class)))) })
public String getAllPaymentTypes(@Context final UriInfo uriInfo,
public List<PaymentTypeData> getAllPaymentTypes(
@QueryParam("onlyWithCode") @Parameter(description = "onlyWithCode") final boolean onlyWithCode) {
this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
Collection<PaymentTypeData> paymentTypes = null;
if (onlyWithCode) {
paymentTypes = this.readPlatformService.retrieveAllPaymentTypesWithCode();
} else {
paymentTypes = this.readPlatformService.retrieveAllPaymentTypes();
}
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS);
securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
return onlyWithCode ? readPlatformService.retrieveAllPaymentTypesWithCode() : readPlatformService.retrieveAllPaymentTypes();
}
@GET
@@ -91,15 +77,11 @@ public class PaymentTypeApiResource {
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Retrieve a Payment Type", description = "Retrieves a payment type")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.GetPaymentTypesPaymentTypeIdResponse.class))) })
public String retrieveOnePaymentType(@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId,
@Context final UriInfo uriInfo) {
this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
this.paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
final PaymentTypeData paymentTypes = this.readPlatformService.retrieveOne(paymentTypeId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS);
public PaymentTypeData retrieveOnePaymentType(
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
return readPlatformService.retrieveOne(paymentTypeId);
}
@POST
@@ -107,16 +89,16 @@ public class PaymentTypeApiResource {
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a Payment Type", description = "Creates a new Payment type\n\n" + "Mandatory Fields: name\n\n"
+ "Optional Fields: Description, isCashPayment,Position")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PostPaymentTypesRequest.class)))
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PostPaymentTypesResponse.class))) })
public String createPaymentType(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
public CommandProcessingResult createPaymentType(@Parameter(hidden = true) PaymentTypeRequest paymentTypeRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaymentType().withJson(apiRequestBodyAsJson).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaymentType()
.withJson(jsonSerializer.serialize(paymentTypeRequest)).build();
final CommandProcessingResult result = this.commandWritePlatformService.logCommandSource(commandRequest);
return this.jsonSerializer.serialize(result);
CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
return result;
}
@PUT
@@ -127,15 +109,15 @@ public class PaymentTypeApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdResponse.class))) })
public String updatePaymentType(@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId,
public CommandProcessingResult updatePaymentType(
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePaymentType(paymentTypeId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandWritePlatformService.logCommandSource(commandRequest);
return this.jsonSerializer.serialize(result);
final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
return result;
}
@DELETE
@@ -145,13 +127,14 @@ public class PaymentTypeApiResource {
@Operation(summary = "Delete a Payment Type", description = "Deletes payment type")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.DeletePaymentTypesPaymentTypeIdResponse.class))) })
public String deleteCode(@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
public CommandProcessingResult deleteCode(
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deletePaymentType(paymentTypeId).build();
final CommandProcessingResult result = this.commandWritePlatformService.logCommandSource(commandRequest);
final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
return this.jsonSerializer.serialize(result);
return result;
}
}
@@ -48,46 +48,6 @@ public final class PaymentTypeApiResourceSwagger {
public Boolean isSystemDefined;
}
@Schema(description = "GetPaymentTypesPaymentTypeIdResponse")
public static final class GetPaymentTypesPaymentTypeIdResponse {
private GetPaymentTypesPaymentTypeIdResponse() {}
@Schema(example = "13")
public Long id;
@Schema(example = "cash")
public String name;
@Schema(example = "cash Payment")
public String description;
@Schema(example = "true")
public Boolean isCashPayment;
@Schema(example = "1")
public Integer position;
@Schema(example = "REPAYMENT_REFUND")
public String codeName;
@Schema(example = "false")
public Boolean isSystemDefined;
}
@Schema(description = "PostPaymentTypesRequest")
public static final class PostPaymentTypesRequest {
private PostPaymentTypesRequest() {}
@Schema(example = "cash")
public String name;
@Schema(example = "cash payment type")
public String description;
@Schema(example = "true")
public Boolean isCashPayment;
@Schema(example = "1")
public Integer position;
@Schema(example = "REPAYMENT_REFUND")
public String codeName;
@Schema(example = "false")
public Boolean isSystemDefined;
}
@Schema(description = "PostPaymentTypesResponse")
public static final class PostPaymentTypesResponse {
@@ -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.portfolio.paymenttype.data.request;
import java.io.Serial;
import java.io.Serializable;
public record PaymentTypeRequest(String name, String description, Boolean isCashPayment, Integer position, String codeName,
Boolean isSystemDefined) implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
@@ -18,14 +18,14 @@
*/
package org.apache.fineract.portfolio.paymenttype.service;
import java.util.Collection;
import java.util.List;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
public interface PaymentTypeReadPlatformService {
Collection<PaymentTypeData> retrieveAllPaymentTypes();
List<PaymentTypeData> retrieveAllPaymentTypes();
Collection<PaymentTypeData> retrieveAllPaymentTypesWithCode();
List<PaymentTypeData> retrieveAllPaymentTypesWithCode();
PaymentTypeData retrieveOne(Long paymentTypeId);
@@ -18,7 +18,6 @@
*/
package org.apache.fineract.portfolio.paymenttype.service;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -37,7 +36,7 @@ public class PaymentTypeReadPlatformServiceImpl implements PaymentTypeReadPlatfo
@Override
@Cacheable(value = "payment_types", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('payment_types')")
public Collection<PaymentTypeData> retrieveAllPaymentTypes() {
public List<PaymentTypeData> retrieveAllPaymentTypes() {
// TODO Auto-generated method stub
this.context.authenticatedUser();
@@ -47,7 +46,7 @@ public class PaymentTypeReadPlatformServiceImpl implements PaymentTypeReadPlatfo
@Override
@Cacheable(value = "paymentTypesWithCode", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('payment_types')")
public Collection<PaymentTypeData> retrieveAllPaymentTypesWithCode() {
public List<PaymentTypeData> retrieveAllPaymentTypesWithCode() {
// TODO Auto-generated method stub
this.context.authenticatedUser();