Skip to content

Commit

Permalink
FINERACT-1971: update and delete interest pause by external id
Browse files Browse the repository at this point in the history
  • Loading branch information
kulminsky authored and adamsaghy committed Jan 20, 2025
1 parent 001797b commit 9258be7
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3759,6 +3759,15 @@ public CommandWrapperBuilder deleteInterestPause(final long loanId, final long v
return this;
}

public CommandWrapperBuilder deleteInterestPause(final String loanExternalId, final long variationId) {
this.actionName = "DELETE";
this.entityName = "INTEREST_PAUSE";
this.loanExternalId = new ExternalId(loanExternalId);
this.entityId = variationId;
this.href = "/v1/loans/external-id/" + loanExternalId + "/interest-pauses/" + variationId;
return this;
}

public CommandWrapperBuilder updateInterestPause(final long loanId, final long variationId) {
this.actionName = "UPDATE";
this.entityName = "INTEREST_PAUSE";
Expand All @@ -3767,4 +3776,13 @@ public CommandWrapperBuilder updateInterestPause(final long loanId, final long v
this.href = "/v1/loans/" + loanId + "/interest-pauses/" + variationId;
return this;
}

public CommandWrapperBuilder updateInterestPause(final String loanExternalId, final long variationId) {
this.actionName = "UPDATE";
this.entityName = "INTEREST_PAUSE";
this.loanExternalId = new ExternalId(loanExternalId);
this.entityId = variationId;
this.href = "/v1/loans/external-id/" + loanExternalId + "/interest-pauses/" + variationId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

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;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -64,7 +67,8 @@ public class LoanInterestPauseApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a new interest pause period for a loan", description = "Allows users to define a period during which no interest will be accrued for a specific loan.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Command successfully processed", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) })
public CommandProcessingResult createInterestPause(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
@RequestBody(required = true) final InterestPauseRequestDto request) {

Expand All @@ -80,7 +84,8 @@ public CommandProcessingResult createInterestPause(@PathParam("loanId") @Paramet
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a new interest pause for a loan using external ID", description = "Allows users to define a period during which no interest will be accrued for a specific loan using the external loan ID.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Command successfully processed", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) })
public CommandProcessingResult createInterestPauseByExternalId(
@PathParam("loanExternalId") @Parameter(description = "loanExternalId") final String loanExternalId,
@RequestBody(required = true) final InterestPauseRequestDto request) {
Expand All @@ -97,7 +102,8 @@ public CommandProcessingResult createInterestPauseByExternalId(
@Path("/{loanId}/interest-pauses")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve all interest pause periods for a loan", description = "Fetches a list of all active interest pause periods for a specific loan.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
@ApiResponses({
@ApiResponse(responseCode = "200", description = "List of interest pause periods", content = @Content(array = @ArraySchema(schema = @Schema(implementation = InterestPauseResponseDto.class)))) })
public List<InterestPauseResponseDto> retrieveInterestPauses(
@PathParam("loanId") @Parameter(description = "loanId") final Long loanId) {

Expand All @@ -110,7 +116,8 @@ public List<InterestPauseResponseDto> retrieveInterestPauses(
@Path("/external-id/{loanExternalId}/interest-pauses")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve all interest pause periods for a loan using external ID", description = "Fetches a list of all active interest pause periods for a specific loan using the external loan ID.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
@ApiResponses({
@ApiResponse(responseCode = "200", description = "List of interest pause periods", content = @Content(array = @ArraySchema(schema = @Schema(implementation = InterestPauseResponseDto.class)))) })
public List<InterestPauseResponseDto> retrieveInterestPausesByExternalId(
@PathParam("loanExternalId") @Parameter(description = "loanExternalId") final String loanExternalId) {

Expand All @@ -135,12 +142,30 @@ public Response deleteInterestPause(@PathParam("loanId") @Parameter(description
return Response.noContent().build();
}

@DELETE
@Path("/external-id/{loanExternalId}/interest-pauses/{variationId}")
@Operation(summary = "Delete an interest pause period by external id", description = "Deletes a specific interest pause period by its variation ID.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "No Content") })
public Response deleteInterestPauseByExternalId(
@PathParam("loanExternalId") @Parameter(description = "loanExternalId") final String loanExternalId,
@PathParam("variationId") @Parameter(description = "variationId") final Long variationId) {

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

final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteInterestPause(loanExternalId, variationId).build();

this.commandsSourceWritePlatformService.logCommandSource(commandRequest);

return Response.noContent().build();
}

@PUT
@Path("/{loanId}/interest-pauses/{variationId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update an interest pause period", description = "Updates a specific interest pause period by its variation ID.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Command successfully processed", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) })
public CommandProcessingResult updateInterestPause(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
@PathParam("variationId") @Parameter(description = "variationId") final Long variationId,
@RequestBody(required = true) final InterestPauseRequestDto request) {
Expand All @@ -152,4 +177,24 @@ public CommandProcessingResult updateInterestPause(@PathParam("loanId") @Paramet

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

@PUT
@Path("/external-id/{loanExternalId}/interest-pauses/{variationId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update an interest pause period by external id", description = "Updates a specific interest pause period by its variation ID.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Command successfully processed", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) })
public CommandProcessingResult updateInterestPauseByExternalId(
@PathParam("loanExternalId") @Parameter(description = "loanExternalId") final String loanExternalId,
@PathParam("variationId") @Parameter(description = "variationId") final Long variationId,
@RequestBody(required = true) final InterestPauseRequestDto request) {

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

final CommandWrapper commandRequest = new CommandWrapperBuilder().updateInterestPause(loanExternalId, variationId)
.withJson(request.toJson()).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.portfolio.interestpauses.service.InterestPauseWritePlatformService;
import org.springframework.stereotype.Component;

Expand All @@ -34,8 +36,16 @@ public class DeleteInterestPauseCommandHandler implements NewCommandSourceHandle
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
final Long loanId = command.getLoanId();
final ExternalId loanExternalId = command.getLoanExternalId();
final Long termVariationId = command.getResourceId();

return interestPauseService.deleteInterestPause(loanId, termVariationId);
if (loanId != null) {
return interestPauseService.deleteInterestPause(loanId, termVariationId);
} else if (loanExternalId != null) {
return interestPauseService.deleteInterestPause(loanExternalId, termVariationId);
} else {
throw new PlatformApiDataValidationException("validation.msg.missing.loan.id.or.external.id",
"Either loanId or loanExternalId must be provided.", "loanId");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.portfolio.interestpauses.service.InterestPauseWritePlatformService;
import org.springframework.stereotype.Component;

Expand All @@ -34,12 +36,20 @@ public class UpdateInterestPauseCommandHandler implements NewCommandSourceHandle
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
final Long loanId = command.getLoanId();
final ExternalId loanExternalId = command.getLoanExternalId();
final Long termVariationId = command.getResourceId();
final String startDate = command.stringValueOfParameterNamed("startDate");
final String endDate = command.stringValueOfParameterNamed("endDate");
final String dateFormat = command.stringValueOfParameterNamed("dateFormat");
final String locale = command.stringValueOfParameterNamed("locale");

return interestPauseService.updateInterestPause(loanId, termVariationId, startDate, endDate, dateFormat, locale);
if (loanId != null) {
return interestPauseService.updateInterestPause(loanId, termVariationId, startDate, endDate, dateFormat, locale);
} else if (loanExternalId != null) {
return interestPauseService.updateInterestPause(loanExternalId, termVariationId, startDate, endDate, dateFormat, locale);
} else {
throw new PlatformApiDataValidationException("validation.msg.missing.loan.id.or.external.id",
"Either loanId or loanExternalId must be provided.", "loanId");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ CommandProcessingResult createInterestPause(ExternalId loanExternalId, String st
*/
CommandProcessingResult deleteInterestPause(Long loanId, Long variationId);

/**
* Delete an existing interest pause period for a loan.
*
* @param loanExternalId
* the external ID of the loan
* @param variationId
* the ID of the loan term variation representing the interest pause
* @return the result of the delete operation
*/
CommandProcessingResult deleteInterestPause(ExternalId loanExternalId, Long variationId);

/**
* Update an existing interest pause period for a loan identified by its internal ID.
*
Expand All @@ -88,4 +99,24 @@ CommandProcessingResult createInterestPause(ExternalId loanExternalId, String st
*/
CommandProcessingResult updateInterestPause(Long loanId, Long variationId, String startDateString, String endDateString,
String dateFormat, String locale);

/**
* Update an existing interest pause period for a loan identified by its internal ID.
*
* @param loanExternalId
* the external ID of the loan
* @param variationId
* the ID of the loan term variation representing the interest pause to be updated
* @param startDateString
* the new start date of the interest pause period (inclusive) as a string
* @param endDateString
* the new end date of the interest pause period (inclusive) as a string
* @param dateFormat
* the format of the provided dates (e.g., "yyyy-MM-dd")
* @param locale
* the locale used for parsing the provided dates
* @return the updated loan term variation ID along with the updated fields
*/
CommandProcessingResult updateInterestPause(ExternalId loanExternalId, Long variationId, String startDateString, String endDateString,
String dateFormat, String locale);
}
Loading

0 comments on commit 9258be7

Please sign in to comment.