FINERACT-2169: Apply DTO instead String json in FundsApiResource
This commit is contained in:
committed by
Adam Saghy
parent
04770133d0
commit
c9c01a50e2
@@ -19,10 +19,12 @@
|
||||
package org.apache.fineract.portfolio.fund.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Immutable data object to represent fund data.
|
||||
*/
|
||||
@Getter
|
||||
public final class FundData implements Serializable {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -41,12 +43,4 @@ public final class FundData implements Serializable {
|
||||
this.name = name;
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.client.models.PostFundsRequest;
|
||||
import org.apache.fineract.client.models.FundRequest;
|
||||
import org.apache.fineract.client.services.FundsApi;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -44,7 +44,7 @@ public class FundGlobalInitializerStep implements FineractGlobalInitializerStep
|
||||
fundNames.add(FUNDS_LENDER_A);
|
||||
fundNames.add(FUNDS_LENDER_B);
|
||||
fundNames.forEach(name -> {
|
||||
PostFundsRequest postFundsRequest = new PostFundsRequest();
|
||||
FundRequest postFundsRequest = new FundRequest();
|
||||
postFundsRequest.name(name);
|
||||
try {
|
||||
fundsApi.createFund(postFundsRequest).execute();
|
||||
|
||||
+15
-27
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.fund.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;
|
||||
@@ -34,24 +33,21 @@ import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
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.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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.codes.data.CodeData;
|
||||
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.fund.data.FundData;
|
||||
import org.apache.fineract.portfolio.fund.data.FundRequest;
|
||||
import org.apache.fineract.portfolio.fund.service.FundReadPlatformService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -71,33 +67,28 @@ public class FundsApiResource {
|
||||
private final PlatformSecurityContext context;
|
||||
private final FundReadPlatformService readPlatformService;
|
||||
private final DefaultToApiJsonSerializer<FundData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Retrieve Funds", description = "Returns the list of funds.\n" + "\n" + "Example Requests:\n" + "\n" + "funds")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = FundsApiResourceSwagger.GetFundsResponse.class)))) })
|
||||
public String retrieveFunds(@Context final UriInfo uriInfo) {
|
||||
public List<FundData> retrieveFunds() {
|
||||
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||
final Collection<FundData> funds = readPlatformService.retrieveAllFunds();
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return toApiJsonSerializer.serialize(settings, funds, RESPONSE_DATA_PARAMETERS);
|
||||
return readPlatformService.retrieveAllFunds();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Create a Fund", description = "Creates a Fund")
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FundsApiResourceSwagger.PostFundsRequest.class)))
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FundRequest.class)))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FundsApiResourceSwagger.PostFundsResponse.class))) })
|
||||
public String createFund(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createFund().withJson(apiRequestBodyAsJson).build();
|
||||
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
return toApiJsonSerializer.serialize(result);
|
||||
public CommandProcessingResult createFund(@Parameter(hidden = true) final FundRequest fundRequest) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createFund().withJson(toApiJsonSerializer.serialize(fundRequest))
|
||||
.build();
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -106,13 +97,9 @@ public class FundsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Retrieve a Fund", description = "Returns the details of a Fund.\n" + "\n" + "Example Requests:\n" + "\n"
|
||||
+ "funds/1")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FundsApiResourceSwagger.GetFundsResponse.class))) })
|
||||
public String retrieveFund(@PathParam("fundId") @Parameter(description = "fundId") final Long fundId, @Context final UriInfo uriInfo) {
|
||||
public FundData retrieveFund(@PathParam("fundId") @Parameter(description = "fundId") final Long fundId) {
|
||||
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||
final FundData fund = readPlatformService.retrieveFund(fundId);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return toApiJsonSerializer.serialize(settings, fund, RESPONSE_DATA_PARAMETERS);
|
||||
return readPlatformService.retrieveFund(fundId);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -120,12 +107,13 @@ public class FundsApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Update a Fund", description = "Updates the details of a fund.")
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FundsApiResourceSwagger.PutFundsFundIdRequest.class)))
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FundRequest.class)))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FundsApiResourceSwagger.PutFundsFundIdResponse.class))) })
|
||||
public String updateFund(@PathParam("fundId") @Parameter(description = "fundId") final Long fundId,
|
||||
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFund(fundId).withJson(apiRequestBodyAsJson).build();
|
||||
@Parameter(hidden = true) final FundRequest fundRequest) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFund(fundId)
|
||||
.withJson(toApiJsonSerializer.serialize(fundRequest)).build();
|
||||
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
return toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
+1
-20
@@ -27,26 +27,6 @@ final class FundsApiResourceSwagger {
|
||||
|
||||
private FundsApiResourceSwagger() {}
|
||||
|
||||
@Schema(description = "GetFundsResponse")
|
||||
public static final class GetFundsResponse {
|
||||
|
||||
private GetFundsResponse() {}
|
||||
|
||||
@Schema(example = "1")
|
||||
public Long id;
|
||||
@Schema(example = "EU Agri Fund")
|
||||
public String name;
|
||||
}
|
||||
|
||||
@Schema(description = "PostFundsRequest")
|
||||
public static final class PostFundsRequest {
|
||||
|
||||
private PostFundsRequest() {}
|
||||
|
||||
@Schema(example = "EU Agri Fund")
|
||||
public String name;
|
||||
}
|
||||
|
||||
@Schema(description = "PostFundsResponse")
|
||||
public static final class PostFundsResponse {
|
||||
|
||||
@@ -63,6 +43,7 @@ final class FundsApiResourceSwagger {
|
||||
|
||||
@Schema(example = "EU Agri Fund (2010-2020)")
|
||||
public String name;
|
||||
private String externalId;
|
||||
}
|
||||
|
||||
@Schema(description = "PutFundsFundIdResponse")
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.fund.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class FundRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private String externalId;
|
||||
}
|
||||
+2
-2
@@ -18,12 +18,12 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.fund.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.portfolio.fund.data.FundData;
|
||||
|
||||
public interface FundReadPlatformService {
|
||||
|
||||
Collection<FundData> retrieveAllFunds();
|
||||
List<FundData> retrieveAllFunds();
|
||||
|
||||
FundData retrieveFund(Long fundId);
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ package org.apache.fineract.portfolio.fund.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.portfolio.fund.data.FundData;
|
||||
@@ -55,7 +55,7 @@ public class FundReadPlatformServiceImpl implements FundReadPlatformService {
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "funds", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('fn')")
|
||||
public Collection<FundData> retrieveAllFunds() {
|
||||
public List<FundData> retrieveAllFunds() {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user