Skip to content

Conversation

@andrew2net
Copy link

@andrew2net andrew2net commented Feb 27, 2025

This PR allows payment for a given loan to be created using a JSON API call. The following features and enhancements have been implemented:

  1. Payment Creation:
  • Added the ability to create payments for a loan.
  • Payments store the payment date and amount.
  • Ensured that a payment cannot be created if it exceeds the outstanding balance of the loan.
  • Added validation errors for cases where a payment cannot be created.
  1. Outstanding Balance Calculation:
  • Exposed the outstanding balance for a given loan in the JSON response for the LoansController#show and LoansController#index.
  • The outstanding balance is calculated as the funded_amount minus the sum of all payment amounts.
  1. Endpoints for Payments:
  • Added an endpoint /loans/:loan_id/payments to retrieve all payments for a given loan.
  • Added an endpoint /loans/:loan_id/payments/:id to retrieve an individual payment.
  1. Thread Safety: Ensured thread safety when creating payments to prevent race conditions and maintain data integrity.

Changes

  • Models:

    • Loan: Added outstanding_balance method to calculate the remaining balance.
    • Created a Payment model and added validation to ensure a payment amount does not exceed the loan's outstanding balance.
  • Controllers:

    • LoansController: Updated index and show actions to include outstanding_balance in the JSON response.
    • Created PaymentsController and added index, show, and create actions to handle payment retrieval and creation.
  • Specs:

    • Added tests for LoansController to verify the inclusion of outstanding_balance in the response.
    • Added tests for PaymentsController to verify payment creation and retrieval.
    • Added tests for the Payment model to ensure thread safety and validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant