-
Notifications
You must be signed in to change notification settings - Fork 4
Added support for Borrow Request #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
educare-kumapuru
wants to merge
1
commit into
main
Choose a base branch
from
borrowRequest-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,101 +1,101 @@ | ||
| <?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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.7.17</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>educare</groupId> | ||
| <artifactId>unitylend</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <packaging>war</packaging> | ||
| <name>unitylend</name> | ||
| <description>UnityLend fosters financial cooperation and empowerment within communities</description> | ||
| <properties> | ||
| <java.version>17</java.version> | ||
| <mybatis.spring.boot.version>3.0.0</mybatis.spring.boot.version> | ||
| <log4j2.version>2.17.1</log4j2.version> | ||
| <spring.aspects.version>3.2.0.RELEASE</spring.aspects.version> | ||
| </properties> | ||
| 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> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.7.17</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>educare</groupId> | ||
| <artifactId>unitylend</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <packaging>war</packaging> | ||
| <name>unitylend</name> | ||
| <description>UnityLend fosters financial cooperation and empowerment within communities</description> | ||
| <properties> | ||
| <java.version>17</java.version> | ||
| <mybatis.spring.boot.version>3.0.0</mybatis.spring.boot.version> | ||
| <log4j2.version>2.17.1</log4j2.version> | ||
| <spring.aspects.version>3.2.0.RELEASE</spring.aspects.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <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> | ||
| <artifactId>spring-boot-starter-actuator</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-configuration-processor</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-aspects</artifactId> | ||
| <version>${spring.aspects.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mybatis.spring.boot</groupId> | ||
| <artifactId>mybatis-spring-boot-starter</artifactId> | ||
| <version>${mybatis.spring.boot.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.postgresql</groupId> | ||
| <artifactId>postgresql</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- <dependency>--> | ||
| <!-- <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> | ||
| <artifactId>spring-boot-starter-actuator</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-configuration-processor</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-aspects</artifactId> | ||
| <version>${spring.aspects.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mybatis.spring.boot</groupId> | ||
| <artifactId>mybatis-spring-boot-starter</artifactId> | ||
| <version>${mybatis.spring.boot.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.postgresql</groupId> | ||
| <artifactId>postgresql</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| <configuration> | ||
| <image> | ||
| <builder>paketobuildpacks/builder-jammy-base:latest</builder> | ||
| </image> | ||
| <excludes> | ||
| <exclude> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </exclude> | ||
| <exclude> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-clean-plugin</artifactId> | ||
| </exclude> | ||
| </excludes> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| <configuration> | ||
| <image> | ||
| <builder>paketobuildpacks/builder-jammy-base:latest</builder> | ||
| </image> | ||
| <excludes> | ||
| <exclude> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </exclude> | ||
| <exclude> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-clean-plugin</artifactId> | ||
| </exclude> | ||
| </excludes> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
| </project> |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/educare/unitylend/controller/BorrowReqController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.educare.unitylend.controller; | ||
|
|
||
| import com.educare.unitylend.Exception.ControllerException; | ||
| import com.educare.unitylend.Exception.ServiceException; | ||
| import com.educare.unitylend.dao.BorrowReqRepository; | ||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import com.educare.unitylend.model.User; | ||
| import com.educare.unitylend.service.BorrowReqService; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| 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("/all-borrow-requests") | ||
| public class BorrowReqController extends BaseController{ | ||
| BorrowReqService borrowReqService; | ||
| @GetMapping("/{userId}") | ||
| public List<BorrowRequest> getAllRequests(@PathVariable String userId) throws ControllerException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestList = borrowReqService.getBorrowRequests(userId); | ||
| return borrowRequestList; | ||
| } catch (ServiceException e) { | ||
| log.error("Error encountered in getting the borrow requests of user"); | ||
| throw new ControllerException("Error encountered in getting the borrow requests", e); | ||
| } | ||
| } | ||
| // new | ||
| @GetMapping("/{userId}/{communityId}") | ||
| public List<BorrowRequest> getRequestsForUserAndCommunity( | ||
| @PathVariable String userId, | ||
| @PathVariable String communityId | ||
| ) throws ControllerException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestList = borrowReqService.getRequestsForUserAndCommunity(userId, communityId); | ||
| return borrowRequestList; | ||
| } catch (Exception e) { | ||
| log.error("Error encountered in getting the borrow requests for particular community", e); | ||
| throw new ControllerException("Error encountered in getting the borrow requests for particular community", e); | ||
| } | ||
| } | ||
|
|
||
| @GetMapping("/user/{userId}/target-amount/{amount}") | ||
| public List<BorrowRequest> getRequestsForUserAndCommunity( | ||
| @PathVariable String userId, | ||
| @PathVariable double amount | ||
| ) throws ControllerException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestListByAmount = borrowReqService.getRequestsByCommunityAndAmount(userId, amount); | ||
| return borrowRequestListByAmount; | ||
| } catch (Exception e) { | ||
| log.error("Error encountered in getting the borrow requests filtered by amount", e); | ||
| throw new ControllerException("Error encountered in getting the borrow requests filtered by amount", e); | ||
| } | ||
| } | ||
| // new ends | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/main/java/com/educare/unitylend/dao/BorrowReqRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.educare.unitylend.dao; | ||
|
|
||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import com.educare.unitylend.model.User; | ||
| import org.apache.ibatis.annotations.Mapper; | ||
| import org.apache.ibatis.annotations.Select; | ||
| import org.apache.ibatis.annotations.Param; | ||
| import org.springframework.stereotype.Repository; | ||
| import java.util.List; | ||
|
|
||
| @Mapper | ||
| @Repository | ||
| public interface BorrowReqRepository { | ||
| @Select(SELECT_REQUESTS_FOR_USER) | ||
| List<BorrowRequest> getAllRequests(@Param("userId") String userId); | ||
|
|
||
| @Select(SELECT_REQUESTS_FOR_USER_AND_COMMUNITY) | ||
| List<BorrowRequest> getAllRequestsForUserAndCommunity( | ||
| @Param("userId") String userId, | ||
| @Param("communityId") String communityId | ||
| ); | ||
|
|
||
| @Select(SELECT_REQUESTS_BY_COMMUNITY_AND_AMOUNT) | ||
| List<BorrowRequest> getAllRequestsByCommunityAndAmount( | ||
| @Param("userId") String userId, | ||
| @Param("amount") double amount | ||
| ); | ||
| static final String SELECT_REQUESTS_FOR_USER = "SELECT * FROM borrow_request WHERE communityid IN " + | ||
| "(SELECT communityid FROM usercommunity WHERE userid = #{userId})"; | ||
|
|
||
| static final String SELECT_REQUESTS_FOR_USER_AND_COMMUNITY = | ||
| "SELECT br.* FROM borrow_request br " + | ||
| "WHERE br.communityid IN (SELECT communityid FROM usercommunity WHERE userid = #{userId}) " + | ||
| "AND br.communityid = #{communityId}"; | ||
|
|
||
| static final String SELECT_REQUESTS_BY_COMMUNITY_AND_AMOUNT = | ||
| "SELECT br.* FROM borrow_request br " + | ||
| "WHERE br.communityid IN (" + | ||
| " SELECT communityid FROM usercommunity WHERE userid = #{userId}" + | ||
| ") AND br.targetamount >= #{amount}"; | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/educare/unitylend/service/BorrowReqService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.educare.unitylend.service; | ||
|
|
||
| import com.educare.unitylend.Exception.ServiceException; | ||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import com.educare.unitylend.model.User; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface BorrowReqService { | ||
| List<BorrowRequest> getBorrowRequests(String userId) throws ServiceException; | ||
| List<BorrowRequest> getRequestsForUserAndCommunity(String userId, String communityId) throws ServiceException; | ||
| List<BorrowRequest> getRequestsByCommunityAndAmount(String userId, double amount) throws ServiceException; | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/educare/unitylend/service/impl/BorrowServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.educare.unitylend.service.impl; | ||
|
|
||
| import com.educare.unitylend.Exception.ServiceException; | ||
| import com.educare.unitylend.dao.BorrowReqRepository; | ||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import com.educare.unitylend.model.User; | ||
| import com.educare.unitylend.service.BorrowReqService; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.ibatis.annotations.Param; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
| @Slf4j | ||
| @AllArgsConstructor | ||
| @Service | ||
| public class BorrowServiceImpl implements BorrowReqService { | ||
| private BorrowReqRepository borrowReqRepository; | ||
| @Override | ||
| public List<BorrowRequest> getBorrowRequests(String userId) throws ServiceException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestList = borrowReqRepository.getAllRequests(userId); | ||
| return borrowRequestList; | ||
| } catch (Exception e) { | ||
| log.error("Error encountered during user fetch operation"); | ||
| throw new ServiceException("Error encountered during user fetch operation", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public List<BorrowRequest> getRequestsForUserAndCommunity(String userId, String communityId) throws ServiceException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestListForComm = borrowReqRepository.getAllRequestsForUserAndCommunity(userId,communityId); | ||
| return borrowRequestListForComm; | ||
| } catch (Exception e) { | ||
| log.error("Error encountered during Borrow request for community fetch operation"); | ||
| throw new ServiceException("Error encountered during Borrow request for community fetch operation", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public List<BorrowRequest> getRequestsByCommunityAndAmount(String userId, double amount) throws ServiceException { | ||
| try { | ||
| List<BorrowRequest> borrowRequestListByAmount = borrowReqRepository.getAllRequestsByCommunityAndAmount(userId,amount); | ||
| return borrowRequestListByAmount; | ||
| } catch (Exception e) { | ||
| log.error("Error encountered during Borrow request filtered by amount fetch operation"); | ||
| throw new ServiceException("Error encountered during Borrow request filtered by amount fetch operation", e); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here , all apis should have community id filter applied to it, because on a community landing page , only requests of that community should be displayed.
Instead of Path Variable User id, community id should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are APIs for users, and will create separate APIs for the community lending page.