add payments functionality #40
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows payment for a given loan to be created using a JSON API call. The following features and enhancements have been implemented:
LoansController#showandLoansController#index.funded_amountminus the sum of all payment amounts./loans/:loan_id/paymentsto retrieve all payments for a given loan./loans/:loan_id/payments/:idto retrieve an individual payment.Changes
Models:
Loan: Addedoutstanding_balancemethod to calculate the remaining balance.Paymentmodel and added validation to ensure a payment amount does not exceed the loan's outstanding balance.Controllers:
LoansController: Updated index and show actions to includeoutstanding_balancein the JSON response.PaymentsControllerand addedindex,show, andcreateactions to handle payment retrieval and creation.Specs:
LoansControllerto verify the inclusion ofoutstanding_balancein the response.PaymentsControllerto verify payment creation and retrieval.Paymentmodel to ensure thread safety and validation.