-
Notifications
You must be signed in to change notification settings - Fork 4
Implemented-Borrow -request- actions #33
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
VaniThapar
wants to merge
18
commits into
main
Choose a base branch
from
borrow-request-actions
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
Show all changes
18 commits
Select commit
Hold shift + click to select a range
25f4d09
Move the DB schema under resources folder
Prathyusha5c0 08919bf
Resolved Issue 9, 10 & 12
Prathyusha5c0 86d1fcb
Resolved Issue 9, 10 & 12
Prathyusha5c0 07d5635
Resolved Issue 9, 10 & 12
Prathyusha5c0 72b2930
Resolved Issue 9, 10 & 12
Prathyusha5c0 7de0820
Resolved Issue 9, 10 & 12
Prathyusha5c0 d1a4494
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 cb66107
Resolved Issue 9, 10 & 12
Prathyusha5c0 046509a
Resolved Issues 9, 10 & 12
Prathyusha5c0 656e2c5
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 488cf2e
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 53cb031
Merge pull request #18 from Prathyusha5c0/prathyusha
NehaKariya0309 faf9a17
Get communities associated with a given userId
Prathyusha5c0 4f58065
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 8930a4d
Merge pull request #24 from Prathyusha5c0/prathyusha
Prathyusha5c0 6b99b8f
Merge pull request #25 from VaniThapar/user-and-community-feature
VaniThapar 1c8facd
added-borrow-request-features
VaniThapar 0408170
added-borrow-request-features
VaniThapar 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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/educare/unitylend/controller/BorrowRequestController.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,65 @@ | ||
| package com.educare.unitylend.controller; | ||
|
|
||
| import com.educare.unitylend.Exception.ControllerException; | ||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import com.educare.unitylend.service.BorrowRequestService; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @AllArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/borrow-request") | ||
| public class BorrowRequestController extends BaseController{ | ||
| BorrowRequestService borrowRequestService; | ||
| @GetMapping("/{userId}") | ||
| public ResponseEntity<List<String>> getAllCommunities(@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<String> communityList = borrowRequestService.getRequestedCommunitiesByUserId(userId); | ||
|
|
||
| if (communityList == null || communityList.isEmpty()) { | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
|
|
||
| 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("/request") | ||
| public ResponseEntity<String> raiseBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ControllerException { | ||
| try { | ||
| String userId = borrowRequest.getBorrowerId(); | ||
|
|
||
| if (userId == null || userId.isEmpty()) { | ||
| return ResponseEntity.badRequest().body("User ID cannot be null or empty"); | ||
| } | ||
|
|
||
| boolean isBorrowRequestSuccessful = borrowRequestService.raiseBorrowRequestByUserId(userId,borrowRequest); | ||
|
|
||
| if (isBorrowRequestSuccessful) { | ||
| borrowRequestService.createBorrowRequest(borrowRequest); | ||
| return ResponseEntity.ok("Raised Borrow Request"); | ||
| } else { | ||
| return ResponseEntity.ok("Cannot make borrow request as your EMI is greater than 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); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
64 changes: 64 additions & 0 deletions
64
src/main/java/com/educare/unitylend/controller/CommunityController.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.model.Community; | ||
| import com.educare.unitylend.service.CommunityService; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @AllArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/community") | ||
| public class CommunityController extends BaseController { | ||
| CommunityService communityService; | ||
|
|
||
| @GetMapping("all-communities") | ||
| public ResponseEntity<?> getAllCommunities() throws ControllerException { | ||
| try { | ||
| List<Community> communityList = communityService.getCommunities(); | ||
|
|
||
| if (communityList.isEmpty()) { | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found"); | ||
| } | ||
|
|
||
| return ResponseEntity.ok(communityList); | ||
| } catch (ServiceException e) { | ||
| log.error("Error encountered in getting the communities", e); | ||
| throw new ControllerException("Error encountered in getting the communities", e); | ||
| } | ||
| } | ||
|
|
||
| @GetMapping("get-community-by-tag") | ||
| public ResponseEntity<?> getCommunityWithTag(@RequestParam String commonTag) throws ControllerException { | ||
| try { | ||
| String communityName = communityService.getCommunityName(commonTag); | ||
|
|
||
| if (communityName == null || communityName.isEmpty()) { | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found"); | ||
| } | ||
|
|
||
| return ResponseEntity.ok(communityName); | ||
| } catch (ServiceException e) { | ||
| log.error("Error encountered in getting the community by tag", e); | ||
| throw new ControllerException("Error encountered in getting the community by tag", e); | ||
| } | ||
| } | ||
|
|
||
| @PostMapping("/create-community") | ||
| public ResponseEntity<String> createNewCommunity(@RequestBody Community community) throws ControllerException { | ||
| try { | ||
| 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); | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/educare/unitylend/controller/UserCommunityController.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,35 @@ | ||
| package com.educare.unitylend.controller; | ||
|
|
||
| import com.educare.unitylend.Exception.ControllerException; | ||
| 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("/usercommunity") | ||
| public class UserCommunityController { | ||
|
|
||
| private UserCommunityService usercommunityService; | ||
| @GetMapping("/{userId}") | ||
| public ResponseEntity<List<String>> getAllCommunities(@PathVariable String userId) throws ControllerException { | ||
| try { | ||
| List<String> communityList = usercommunityService.getCommunitiesByUserId(userId); | ||
| 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); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.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,26 @@ | ||
| package com.educare.unitylend.dao; | ||
|
|
||
| import com.educare.unitylend.model.BorrowRequest; | ||
| import org.apache.ibatis.annotations.Insert; | ||
| 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.util.List; | ||
|
|
||
| @Mapper | ||
| @Repository | ||
| public interface BorrowRequestRepository { | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| @Select("SELECT Community.CommunityName " + | ||
| "FROM Borrow_Request " + | ||
| "JOIN Community ON Borrow_Request.CommunityID = Community.CommunityId " + | ||
| "WHERE Borrow_Request.BorrowerId = #{userId}") | ||
| List<String> getBorrowRequestByUserId(@Param("userId") String userId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the functionality, The function name should be |
||
|
|
||
| @Insert("INSERT INTO Borrow_Request (RequestID, BorrowerID, CommunityID, ReturnPeriod, Status, TargetAmount) " + | ||
| "VALUES (uuid_generate_v4(), #{borrowRequest.borrowerId}, #{borrowRequest.community.communityid}, CAST (#{borrowRequest.returnPeriod} AS INTEGER), #{borrowRequest.status}, #{borrowRequest.targetAmount})") | ||
| void createBorrowRequest(@Param("borrowRequest") BorrowRequest borrowRequest); | ||
|
|
||
| } | ||
35 changes: 35 additions & 0 deletions
35
src/main/java/com/educare/unitylend/dao/CommunityRepository.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,35 @@ | ||
| package com.educare.unitylend.dao; | ||
|
|
||
| import com.educare.unitylend.model.Community; | ||
| import org.apache.ibatis.annotations.Insert; | ||
| import org.apache.ibatis.annotations.Mapper; | ||
| import org.apache.ibatis.annotations.Select; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Mapper | ||
| @Repository | ||
|
|
||
| public interface CommunityRepository { | ||
| @Select("select * from community") | ||
| List<Community> getAllCommunities(); | ||
|
|
||
| @Select("select communityname from community where commontag = #{commontag}") | ||
| String getCommunity(String commontag); | ||
|
|
||
| @Insert("INSERT INTO community (communityid, communityname, commontag) VALUES (uuid_generate_v4(), #{communityname}, #{commontag})") | ||
| void createCommunity(Community community); | ||
|
|
||
| @Insert("INSERT INTO community (communityid, communityname, commontag) VALUES (uuid_generate_v4(), #{name}, #{tag})") | ||
| void createCommunityUsingStrings(String name, String tag); | ||
|
|
||
| @Select("SELECT COUNT(*) > 0 FROM community WHERE commontag = #{commontag}") | ||
| boolean existsByCommontag(String commontag); | ||
|
|
||
| @Select("SELECT commontag FROM community WHERE commontag = #{commontag}") | ||
| String findByCommontag(String commontag); | ||
|
|
||
| @Select("SELECT communityid FROM community WHERE communityname = #{name}") | ||
| String getCommunityIdByName(String name); | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/educare/unitylend/dao/UserCommunityRepository.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,23 @@ | ||
| package com.educare.unitylend.dao; | ||
|
|
||
|
|
||
| import org.apache.ibatis.annotations.Insert; | ||
| 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.util.List; | ||
|
|
||
| @Mapper | ||
| @Repository | ||
| public interface UserCommunityRepository { | ||
| @Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})") | ||
| void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId); | ||
|
|
||
|
|
||
| @Select("SELECT c.CommunityName FROM Community c JOIN UserCommunity uc ON c.CommunityId = uc.CommunityId WHERE uc.UserId = #{userId}") | ||
| List<String> findCommunityNamesByUserId(@Param("userId") String userId); | ||
|
|
||
|
|
||
| } |
Oops, something went wrong.
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.
The function name should be
getCommunitiesForUser()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.
There should be a method for getting the borrowRequest for a given UserId, Community.
And one for Administration purpose to get all the Borrowrequests.