Skip to content

Implemented-Borrow -request- actions#33

Open
VaniThapar wants to merge 18 commits intomainfrom
borrow-request-actions
Open

Implemented-Borrow -request- actions#33
VaniThapar wants to merge 18 commits intomainfrom
borrow-request-actions

Conversation

@VaniThapar
Copy link
Owner

Implemented the following features:

-Have a separate table for borrowing request with all the attributes of borrowing and map with the user table with foreign key
-Validation should be there at service layer for borrow request (i.e - The monthly emi should not be more than half of the monthly income of borrower)
-If a borrowing request is not passing the validations, Return the error message to the UI.
-If borrowing request is validated, Return the success message to the user and insert into DB.
-Think how the mapping of community to borrowing request will happen (User to borrowing request or Community to borrowing request)

@gitguardian
Copy link

gitguardian bot commented Mar 4, 2024

⚠️ GitGuardian has uncovered 8 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9696177 Triggered Username Password 1c8facd src/main/resources/application.properties View secret
9696177 Triggered Username Password 07d5635 src/main/resources/application.properties View secret
9696177 Triggered Username Password 08919bf src/main/resources/application.properties View secret
9696177 Triggered Username Password 6b99b8f src/main/resources/application.properties View secret
9696177 Triggered Username Password faf9a17 src/main/resources/application.properties View secret
9696177 Triggered Username Password 8930a4d src/main/resources/application.properties View secret
9696178 Triggered Generic Password 08919bf src/main/java/com/educare/unitylend/dao/UserRepository.java View secret
9696178 Triggered Generic Password 046509a src/main/java/com/educare/unitylend/dao/UserRepository.java View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@Mapper
@Repository
public interface BorrowRequestRepository {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Add method to fetch borrow request based on community_id, This is required for lenders page.
  2. Modify the schema to have a borrow request multiple communities, You can have a separate table which can have the mapping of community to Borrow request.

@@ -12,12 +10,27 @@
@NoArgsConstructor
@AllArgsConstructor
public class BorrowRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Add @DaTa on the DataClass, Post that there will be no need to add @Getter and @Setter tag on every variable in the class.
  2. Make the change to have many to many community to borrow request map. In this particular POJO this should have List

"FROM Borrow_Request " +
"JOIN Community ON Borrow_Request.CommunityID = Community.CommunityId " +
"WHERE Borrow_Request.BorrowerId = #{userId}")
List<String> getBorrowRequestByUserId(@Param("userId") String userId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the functionality, The function name should be
getCommunitiesForWhichBorrowRequestRaisedByUser()


public interface BorrowRequestService {

List<String> getRequestedCommunitiesByUserId(String userId) throws ServiceException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name should be
getCommunitiesForBorrowrequestRaisedByUser()


List<String> getRequestedCommunitiesByUserId(String userId) throws ServiceException;

boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The function name should be validateBorrowRequest.
  2. I don't think that there is any need to pass userId as BorrowRequest object would already be having the borrower details.


boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException;

void createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should also return boolean value, Whether the borrow request is created successfully in the DB or not.

private BorrowRequestRepository borrowRequestRepository;
public List<String> getRequestedCommunitiesByUserId(String userId) throws ServiceException{
List<String> communities=borrowRequestRepository.getBorrowRequestByUserId(userId);
System.out.println(communities);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use System.out.println instead use log.error, log.info or log.debug

}

public void createBorrowRequest(BorrowRequest borrowRequest) {
borrowRequestRepository.createBorrowRequest(borrowRequest);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a try catch block,
If any error is encountered, Return false.

public boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException {
try {
// Assuming returnPeriod is in days
BigDecimal monthlyInterestRate = new BigDecimal("50.0").divide(new BigDecimal(12 * 100), 10, RoundingMode.HALF_UP);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Move all the constants used to the start of the class, i.e public static final Integer MONTHS_IN_YEAR = 12.
  2. Add interest_rate in the BorrowRequest Object
  3. Add loan tenure in BorrowRequest object.
  4. The validation method here should just calculate the monthly EMI and then validate based on the user income if the user will be able to pay the amount or not, By checking if the user income is double of the EMI or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for calculating the EMI you should have different function calculateEMI(PrincipalAmount, loanPaymentTenure, InterestRate) and this function should utilize that.

public class BorrowRequestController extends BaseController{
BorrowRequestService borrowRequestService;
@GetMapping("/{userId}")
public ResponseEntity<List<String>> getAllCommunities(@PathVariable String userId) throws ControllerException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name should be getCommunitiesForUser()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a method for getting the borrowRequest for a given UserId, Community.

And one for Administration purpose to get all the Borrowrequests.

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.

4 participants