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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ build/

### VS Code ###
.vscode/
pom.xml
src/main/resources/application.properties

### logs ###
logs/

.nfs*


9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ https://drive.google.com/file/d/1gyd7sokLba8Ai6vOULL_auioWAXFHsps/view?usp=drive

![UnityLend drawio](https://github.com/VaniThapar/UnityLend/assets/91086564/d81ee720-ae83-4ba6-810b-1676812c2d48)

# Flow diagram for the lender
Draw.io Link:
https://app.diagrams.net/#G1dLFlWWprYTwwtwjXvi5WEJS94RS7x-uo#%7B%22pageId%22%3A%22W7Y_DPB_WjcdcxQGYy3G%22%7D




# Flow diagram for borrowing request
Draw.io Link:
https://drive.google.com/file/d/1pA5A4blyuBDjGBg7mWg6v0XT-DEOwUn8/view?usp=sharing)https://drive.google.com/file/d/1pA5A4blyuBDjGBg7mWg6v0XT-DEOwUn8/view?usp=sharing



Expand Down
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -43,7 +43,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Changed the scope to provided to use the dependency at runtime for tomcat (external)-->
<scope>provided</scope>

</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -72,6 +72,11 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.4</version> <!-- Use the version compatible with your project -->
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.model.BorrowRequest;
import com.educare.unitylend.model.Community;
import com.educare.unitylend.service.BorrowRequestCommunityService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/borrowrequestcommunity")
public class BorrowRequestCommunityController {

BorrowRequestCommunityService borrowRequestCommunityService;

@GetMapping("/get-communities/{requestId}")
public ResponseEntity<List<?>> getCommunitiesByRequestId(@PathVariable String requestId) throws ControllerException {
//Getting all communities for a given request
try {
if (requestId == null || requestId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("Request ID cannot be null or empty"));
}

List<Community> communityList = borrowRequestCommunityService.getCommunitiesByRequestId(requestId);

if (communityList == null || communityList.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(communityList);
} catch (Exception e) {
log.error("Error encountered in getting the communities with request ID: {}", requestId, e);
throw new ControllerException("Error encountered in getting the communities with request ID", e);
}
}

@GetMapping("/get-requests/{communityId}")
public ResponseEntity<List<?>> getRequestsByCommunityId(@PathVariable String communityId) throws ControllerException {
try {
if (communityId == null || communityId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("Community ID cannot be null or empty"));
}

List<BorrowRequest> requests = borrowRequestCommunityService.getRequestsByCommunityId(communityId);

if (requests == null || requests.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(requests);
} catch (Exception e) {
log.error("Error encountered in getting the requests for community with ID: {}", communityId, e);
throw new ControllerException("Error encountered in getting the requests for community with given ID", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.model.BorrowRequest;
import com.educare.unitylend.model.Community;
import com.educare.unitylend.service.BorrowRequestCommunityService;
import com.educare.unitylend.service.BorrowRequestService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/borrow-request")
public class BorrowRequestController extends BaseController{
BorrowRequestService borrowRequestService;
BorrowRequestCommunityService borrowRequestCommunityService;

@GetMapping("get-requests-by-user/{userId}")
public ResponseEntity<?> getBorrowRequestsByUserId(@PathVariable String userId) throws ControllerException{
try {
if(userId==null || userId.isEmpty()){
return ResponseEntity.badRequest().body(List.of("User ID cannot be null or empty"));
}
List<BorrowRequest> borrowRequestList = borrowRequestService.getBorrowRequestsByUserId(userId);
return ResponseEntity.ok(borrowRequestList);
} catch (ServiceException e) {
log.error("Error encountered in fetching the borrow requests by user id", e);
throw new ControllerException("Error encountered in fetching the borrow requests by user id",e);
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error encountered in validating the user");
}
}

@GetMapping("/get-communities-for-user/{userId}")
public ResponseEntity<?> getCommunitiesForUser(@PathVariable String userId) throws ControllerException {
try {
if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("User ID cannot be null or empty"));
}

List<Community> communityList = borrowRequestService.getCommunitiesForWhichBorrowRequestRaisedByUser(userId);

if (communityList == null || communityList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No communities found where given user has raised a request");
}

return ResponseEntity.ok(communityList);
} catch (Exception e) {
log.error("Error encountered in getting the communities for user with ID: {}", userId, e);
throw new ControllerException("Error encountered in getting the communities", e);
}
}

@PostMapping("/raise-borrow-request")
public ResponseEntity<String> raiseBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ControllerException {
try {
String userId = borrowRequest.getBorrower().getUserId();

if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().body("User ID cannot be null or empty");
}

boolean isBorrowRequestValid = borrowRequestService.validateBorrowRequest(borrowRequest);

if (isBorrowRequestValid) {
borrowRequestService.createBorrowRequest(borrowRequest);
return ResponseEntity.ok("Raised Borrow Request");
} else {
return ResponseEntity.ok("Cannot make borrow request as your Monthly EMI is greater than half of monthly salary");
}
} catch (Exception e) {
log.error("Error encountered in raising borrow request for user with ID: {}", borrowRequest.getBorrower(), e);
throw new ControllerException("Error encountered in getting the communities", e);
}
}


@GetMapping("/get-requests-by-community/{communityId}")
public ResponseEntity<?> getBorrowRequestsByCommunityId(@PathVariable String communityId) throws ControllerException{
try {
if (communityId == null || communityId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("Community ID cannot be null or empty"));
}

List<BorrowRequest> borrowRequestList = borrowRequestCommunityService.getRequestsByCommunityId(communityId);

if (borrowRequestList == null || borrowRequestList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No borrow requests found for given community");
}
return ResponseEntity.ok(borrowRequestList);
} catch (ServiceException e) {
log.error("Error encountered in fetching borrow requests in a community");
throw new ControllerException("Error encountered in fetching borrow requests in a community",e);
}

// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error encountered in validating the community");

}


@GetMapping("/get-requests-by-amount/{communityId}/{amount}")
ResponseEntity<?>getBorrowRequestsByAmount(@PathVariable String communityId, @PathVariable BigDecimal amount) throws ControllerException{
try {
if (communityId == null || communityId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("Community ID cannot be null or empty"));
}

List<BorrowRequest> borrowRequestList = borrowRequestCommunityService.getRequestsByCommunityId(communityId);

if (borrowRequestList == null || borrowRequestList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No borrow requests found for given community and amount");
}

List<BorrowRequest> requiredRequestList=new ArrayList<>();
for(BorrowRequest request:borrowRequestList){
if (request.getRequestedAmount().compareTo(amount) >= 0) {
requiredRequestList.add(request);
}
}

log.info("requiredRequestList is "+ requiredRequestList);
return ResponseEntity.ok(requiredRequestList);
}
catch(ServiceException e){
log.error("Error encountered in fetching borrow requests for the given community and amount");
throw new ControllerException("Error encountered in fetching borrow requests for the given community and amount",e);
}
}

@GetMapping("/get-requests-by-interest/{communityId}/{interest}")
ResponseEntity<?>getBorrowRequestsByInterest(@PathVariable String communityId, @PathVariable BigDecimal interest) throws ControllerException{
try {
if (communityId == null || communityId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("Community ID cannot be null or empty"));
}
List<BorrowRequest> borrowRequestList = borrowRequestCommunityService.getRequestsByCommunityId(communityId);

if (borrowRequestList == null || borrowRequestList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No borrow requests found for given community and amount");
}

List<BorrowRequest> requiredRequestList=new ArrayList<>();
for(BorrowRequest request:borrowRequestList){
if(request.getMonthlyInterestRate().compareTo(interest)<=0){
requiredRequestList.add(request);
}
}
return ResponseEntity.ok(requiredRequestList);
}
catch(ServiceException e){
log.error("Error encountered in fetching borrow requests for the given community and interest");
throw new ControllerException("Error encountered in fetching borrow requests for the given community and interest",e);
}
}

/*For Administration Purpose*/
@GetMapping("/get-all-borrow-requests")
public ResponseEntity<?> getAllBorrowRequests() throws ControllerException {
try {
List<BorrowRequest>borrowRequestList=borrowRequestService.getAllBorrowRequests();

if (borrowRequestList == null || borrowRequestList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No borrow requests created yet");

}

return ResponseEntity.ok(borrowRequestList);
} catch (Exception e) {
log.error("Error encountered in getting all borrow requests", e);
throw new ControllerException("Error encountered in getting all borrow requests", e);
}
}









}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
@AllArgsConstructor
@RestController
@RequestMapping("/community")

public class CommunityController extends BaseController {
CommunityService communityService;

@GetMapping("all-communities")
public ResponseEntity<?> getAllCommunities() throws ControllerException {
//Getting all the existing communities
try {
List<Community> communityList = communityService.getCommunities();

if (communityList.isEmpty()) {
if (communityList == null || communityList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found");
}

Expand All @@ -36,8 +38,13 @@ public ResponseEntity<?> getAllCommunities() throws ControllerException {
}

@GetMapping("get-community-by-tag")
public ResponseEntity<?> getCommunityWithTag(@RequestParam String commonTag) throws ControllerException {
public ResponseEntity<?> getCommunityWithTag(@RequestParam(required = false) String commonTag) throws ControllerException {
//Getting all communities with the given common tag
try {
if (commonTag == null || commonTag.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("commonTag parameter is missing or empty");
}

String communityName = communityService.getCommunityName(commonTag);

if (communityName == null || communityName.isEmpty()) {
Expand All @@ -53,12 +60,18 @@ public ResponseEntity<?> getCommunityWithTag(@RequestParam String commonTag) thr

@PostMapping("/create-community")
public ResponseEntity<String> createNewCommunity(@RequestBody Community community) throws ControllerException {
//Creating a new community with community object
try {
if (community == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Request body is null");
}

communityService.createCommunity(community);
return ResponseEntity.ok("success!!!");
} catch (ServiceException e) {
log.error("Error encountered in creating the community", e);
throw new ControllerException("Error encountered in creating the community", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.educare.unitylend.controller;
import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.service.UserCommunityService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/lendingtransaction")
public class LendingTransactionController {


}
Loading