Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@
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.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.rate.data.RateData;
Expand All @@ -63,60 +59,48 @@ public class RateApiResource {
private final PlatformSecurityContext context;
private final RateReadService readPlatformService;
private final DefaultToApiJsonSerializer<RateData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;

@GET
@Path("{rateId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveRate(@PathParam("rateId") Long rateId, @Context final UriInfo uriInfo) {
public RateData retrieveRate(@PathParam("rateId") Long rateId) {

this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

final RateData rate = this.readPlatformService.retrieveOne(rateId);

final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());

return this.toApiJsonSerializer.serialize(settings, rate, RESPONSE_DATA_PARAMETERS);
return this.readPlatformService.retrieveOne(rateId);
}

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String createRate(final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createRate().withJson(apiRequestBodyAsJson).build();

final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);

return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult createRate(final RateRequest rateRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createRate().withJson(toApiJsonSerializer.serialize(rateRequest))
.build();

return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String getAllRates(@Context final UriInfo uriInfo) {
public List<RateData> getAllRates() {

this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

Collection<RateData> rates = this.readPlatformService.retrieveAllRates();

final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());

return this.toApiJsonSerializer.serialize(settings, rates, RESPONSE_DATA_PARAMETERS);
return readPlatformService.retrieveAllRates();
}

@PUT
@Path("{rateId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updateRate(@PathParam("rateId") Long rateId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateRate(rateId).withJson(apiRequestBodyAsJson).build();

final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
public CommandProcessingResult updateRate(@PathParam("rateId") Long rateId, final RateRequest rateRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateRate(rateId)
.withJson(toApiJsonSerializer.serialize(rateRequest)).build();

return this.toApiJsonSerializer.serialize(result);
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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.rate.api;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RateRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private String name;
private BigDecimal percentage;
private Integer productApply;
private Boolean active;
private String locale;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.fineract.portfolio.rate.service;

import java.util.Collection;
import java.util.List;
import org.apache.fineract.portfolio.rate.data.RateData;

Expand All @@ -27,9 +26,9 @@
*/
public interface RateReadService {

Collection<RateData> retrieveAllRates();
List<RateData> retrieveAllRates();

Collection<RateData> retrieveLoanApplicableRates();
List<RateData> retrieveLoanApplicableRates();

RateData retrieveOne(Long rateId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
Expand All @@ -44,7 +43,7 @@ public class RateReadServiceImpl implements RateReadService {
private final PlatformSecurityContext context;

@Override
public Collection<RateData> retrieveAllRates() {
public List<RateData> retrieveAllRates() {
this.context.authenticatedUser();
final RateMapper rm = new RateMapper();
final String sql = "select " + rm.rateSchema();
Expand Down Expand Up @@ -80,7 +79,7 @@ public RateData retrieveByName(String name) {
}

@Override
public Collection<RateData> retrieveLoanApplicableRates() {
public List<RateData> retrieveLoanApplicableRates() {
this.context.authenticatedUser();
final RateMapper rm = new RateMapper();
final String sql = "select " + rm.rateSchema() + " where r.active = ? and product_apply=?";
Expand Down
Loading