Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ logs/

.nfs*
pom.xml
application.properties
src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,59 +56,62 @@ ResponseEntity<List<BorrowRequest>> getBorrowRequestForUserId(@PathVariable Stri
* @throws ControllerException If an error occurs during the borrow request retrieval process.
*/
@GetMapping("/get-borrow-request-by-community-id/{communityId}")
ResponseEntity<List<BorrowRequest>> getBorrowRequestForCommunity(@PathVariable String communityId) throws ControllerException {
ResponseEntity<List<BorrowRequest>> getBorrowRequestForCommunity() throws ControllerException {
return null;
}


/**
* API endpoint for retrieving borrow requests in a community within an amount range.
*
*@PathVariable String communityId
* @param minAmount The minimum amount of the borrow requests.
* @param maxAmount The maximum amount of the borrow requests.
* @param lessThan Flag indicating if the amount should be less than maxAmount.
* @param greaterThan Flag indicating if the amount should be greater than minAmount.
* @return ResponseEntity<List<BorrowRequest>> The list of borrow requests in the community within the specified amount range.
* @throws ControllerException If an error occurs during the borrow request retrieval process.
*/
@GetMapping("/get-borrow-request-in-community-by-amount")
@PostMapping("/get-borrow-request-in-community-by-amount/{communityId}")
ResponseEntity<List<BorrowRequest>> getBorrowRequestsInCommunityInAmountRange(
@RequestParam(value = "minAmount", required = false) BigDecimal minAmount,
@RequestParam(value = "maxAmount", required = false) BigDecimal maxAmount,
@RequestParam(value = "maxAmount", required = true) BigDecimal maxAmount,
@RequestParam(value = "lessThan", required = false, defaultValue = "false") boolean lessThan,
@RequestParam(value = "greaterThan", required = false, defaultValue = "true") boolean greaterThan
@RequestParam(value = "greaterThan", required = false, defaultValue = "true") boolean greaterThan,
@PathVariable String communityId
) throws ControllerException {
try{
log.info("minAmount: {}", minAmount);
log.info("maxAmount: {}", maxAmount);
log.info("lessThan: {}", lessThan);
log.info("greaterThan: {}", greaterThan);
log.info("communityId: {}", communityId);
List<BorrowRequest> borrowRequests = new ArrayList<>();

if (minAmount != null && maxAmount != null) {
if (minAmount.compareTo(maxAmount) >= 0) {
if (minAmount.compareTo(maxAmount) > 0) {
log.error("minAmount is greater than maxAmount which is not permissible");
return ResponseEntity.badRequest().body(borrowRequests);
}
}

else if(minAmount==null && maxAmount==null){
log.error("Both minAmount and maxAmount are empty");
return ResponseEntity.badRequest().body(borrowRequests);
}

if(lessThan && greaterThan){
log.error("Inaccurate Constrains");
return ResponseEntity.badRequest().body(borrowRequests);
}
else if(lessThan){
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityLessThanAmount(maxAmount);
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityLessThanAmount(maxAmount, communityId);
}
else if(greaterThan){
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityGreaterThanAmount(minAmount);
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityGreaterThanAmount(minAmount, communityId);
}
else{
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityInRange(minAmount,maxAmount);
borrowRequests=borrowRequestService.getBorrowRequestsInCommunityInRange(minAmount,maxAmount, communityId);
}

// log.info(borrowRequests);
return ResponseEntity.ok(borrowRequests);
}

catch(ServiceException e){
log.error("Error in filtering borrow requests based on amount");
throw new ControllerException("Error in filtering borrow requests based on amount",e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,82 @@
package com.educare.unitylend.dao;

import com.educare.unitylend.model.BorrowRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Mapper
@Repository
public interface BorrowRequestRepository {

@Select("SELECT " +
"borrow_request.borrow_request_id AS borrowRequestId," +
"borrow_request.return_period_days AS returnPeriodDays," +
"borrow_request.monthly_interest_rate AS monthlyInterestRate," +
"borrow_request.borrow_status AS borrowStatus," +
"borrow_request.requested_amount AS requestedAmount," +
"borrow_request.collected_amount AS collectedAmount," +
"borrow_request.is_defaulted AS isDefaulted," +
"borrow_request.default_fine AS defaultFine," +
"borrow_request.default_count AS defaultCount," +
"borrow_request.created_at AS createdAt," +
"borrow_request.last_modified_at AS lastModifiedAt " +
"FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " +
"WHERE borrow_request.requested_amount <= #{maxAmount}" +
" AND " +
"borrow_request_community_map.community_id = #{communityId}"
)
List<BorrowRequest> findByRequestedAmountLessThanAndCommunityIdsContaining(
@Param("maxAmount") BigDecimal maxAmount,
@Param("communityId") String communityId
);

@Select("SELECT " +
"borrow_request.borrow_request_id AS borrowRequestId," +
"borrow_request.return_period_days AS returnPeriodDays," +
"borrow_request.monthly_interest_rate AS monthlyInterestRate," +
"borrow_request.borrow_status AS borrowStatus," +
"borrow_request.requested_amount AS requestedAmount," +
"borrow_request.collected_amount AS collectedAmount," +
"borrow_request.is_defaulted AS isDefaulted," +
"borrow_request.default_fine AS defaultFine," +
"borrow_request.default_count AS defaultCount," +
"borrow_request.created_at AS createdAt," +
"borrow_request.last_modified_at AS lastModifiedAt " +
"FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " +
"WHERE borrow_request.requested_amount >= #{minAmount}" +
" AND " +
"borrow_request_community_map.community_id = #{communityId}"
)
List<BorrowRequest> findByRequestedAmountGreaterThanEqualAndCommunityIdsContaining(
@Param("minAmount") BigDecimal minAmount,
@Param("communityId") String communityId);

@Select("SELECT " +
"borrow_request.borrow_request_id AS borrowRequestId," +
"borrow_request.return_period_days AS returnPeriodDays," +
"borrow_request.monthly_interest_rate AS monthlyInterestRate," +
"borrow_request.borrow_status AS borrowStatus," +
"borrow_request.requested_amount AS requestedAmount," +
"borrow_request.collected_amount AS collectedAmount," +
"borrow_request.is_defaulted AS isDefaulted," +
"borrow_request.default_fine AS defaultFine," +
"borrow_request.default_count AS defaultCount," +
"borrow_request.created_at AS createdAt," +
"borrow_request.last_modified_at AS lastModifiedAt " +
"FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " +
"WHERE borrow_request.requested_amount <= #{maxAmount}" +
" AND " + "borrow_request.requested_amount >= #{minAmount}" +
" AND " +
"borrow_request_community_map.community_id = #{communityId}"
)
List<BorrowRequest> findByRequestedAmountBetweenAndCommunityIdsContaining(
@Param("minAmount") BigDecimal minAmount,
@Param("maxAmount") BigDecimal maxAmount,
@Param("communityId") String communityId);

}
4 changes: 3 additions & 1 deletion src/main/java/com/educare/unitylend/model/BorrowRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@AllArgsConstructor
public class BorrowRequest {
private String borrowRequestId;
private User borrower;
private String borrower_id;
private Integer returnPeriodDays;
private BigDecimal monthlyInterestRate;
private Status borrowStatus;
Expand All @@ -28,4 +28,6 @@ public class BorrowRequest {
private LocalDateTime createdAt;
private LocalDateTime lastModifiedAt;
private List<String> communityIds;


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public interface BorrowRequestService {
List<BorrowRequest> getBorrowRequestForCommunity(String communityId) throws ServiceException;
Boolean updateEMIDefaults() throws ServiceException;
Boolean updateBorrowRequestStatus(Status status) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount, String communityId) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount, String communityId) throws ServiceException;
List<BorrowRequest> getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount, String communityId) throws ServiceException;
List<BorrowRequest> getAllBorrowRequests() throws ServiceException;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.educare.unitylend.service.impl;

import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.dao.BorrowRequestRepository;
import com.educare.unitylend.model.BorrowRequest;
import com.educare.unitylend.model.Status;
import com.educare.unitylend.service.BorrowRequestService;
Expand All @@ -15,7 +16,7 @@
@AllArgsConstructor
@Service
public class BorrowRequestServiceImpl implements BorrowRequestService {

BorrowRequestRepository borrowRequestRepository;
@Override
public List<BorrowRequest> getAllBorrowRequests() throws ServiceException {
return null;
Expand Down Expand Up @@ -47,17 +48,32 @@ public Boolean updateBorrowRequestStatus(Status status) throws ServiceException
}

@Override
public List<BorrowRequest> getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount) throws ServiceException {
return null;
public List<BorrowRequest> getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount, String communityId) throws ServiceException {
try {


return borrowRequestRepository.findByRequestedAmountLessThanAndCommunityIdsContaining(maxAmount, communityId);
} catch (Exception e) {
throw new ServiceException("Error retrieving borrow requests with amount less than " + maxAmount, e);
}
}

@Override
public List<BorrowRequest> getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount) throws ServiceException {
return null;
public List<BorrowRequest> getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount, String communityId) throws ServiceException {
try {
return borrowRequestRepository.findByRequestedAmountGreaterThanEqualAndCommunityIdsContaining(minAmount, communityId);
} catch (Exception e) {
throw new ServiceException("Error retrieving borrow requests with amount greater than or equal to " + minAmount, e);
}
}

@Override
public List<BorrowRequest> getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount) throws ServiceException {
return null;
public List<BorrowRequest> getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount, String communityId) throws ServiceException {
try {
return borrowRequestRepository.findByRequestedAmountBetweenAndCommunityIdsContaining(minAmount, maxAmount, communityId);
} catch (Exception e) {
throw new ServiceException("Error retrieving borrow requests with amount between " + minAmount + " and " + maxAmount, e);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.educare.unitylend.service.impl;

import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.dao.UserCommunityRepository;
import com.educare.unitylend.dao.UserCommunityMapRepository;
import com.educare.unitylend.model.User;
import com.educare.unitylend.service.UserCommunityService;
import com.educare.unitylend.service.UserService;
Expand All @@ -15,12 +15,12 @@
@AllArgsConstructor
@Service
public class UserCommunityServiceImpl implements UserCommunityService {
private UserCommunityRepository userCommunityRepository;
private UserCommunityMapRepository userCommunityRepository;
public List<String> getCommunitiesByUserId(String userId) throws ServiceException{
try {
List<String> communityNames = userCommunityRepository.findCommunityNamesByUserId(userId);
try { return null;
// List<String> communityNames = userCommunityRepository.findCommunityNamesByUserId(userId);
// log.info("communityNames: ", communityNames);
return communityNames;
//return communityNames;
} catch (Exception e) {
log.error("Error encountered during community fetching operation for user with ID: {}", userId, e);
throw new ServiceException("Error encountered during community fetch operation", e);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

server.port=8085

spring.datasource.url=jdbc:postgresql://localhost:5432/unity-lend
spring.datasource.url=jdbc:postgresql://localhost:5432/final
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.password=UnityLend
spring.datasource.driver-class-name=org.postgresql.Driver

Loading