diff --git a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java index 3e2531e..a8b2778 100644 --- a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java +++ b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java @@ -1,14 +1,43 @@ package com.educare.unitylend.controller; -import com.educare.unitylend.service.BorrowRequestCommunityMapService; +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.BorrowRequest; +import com.educare.unitylend.model.Status; 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.*; -@Slf4j -@AllArgsConstructor -@RestController -@RequestMapping("/borrow-request") +import java.util.List; + public class BorrowRequestController extends BaseController{ -} \ No newline at end of file + + ResponseEntity> getAllBorrowRequests() throws ServiceException { + return null; + } + + ResponseEntity> getBorrowRequestForUserId(String userId) throws ServiceException { + return null; + } + + ResponseEntity createBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ServiceException { + return null; + } + + ResponseEntity> getBorrowRequestForCommunity(@RequestParam List communityId) throws ServiceException { + return null; + } + + ResponseEntity updateEMIDefaults() throws ServiceException { + return null; + } + + ResponseEntity updateBorrowRequestStatus(@RequestBody Status status) throws ServiceException { + return null; + } +} + + + diff --git a/src/main/java/com/educare/unitylend/controller/TransactionController.java b/src/main/java/com/educare/unitylend/controller/TransactionController.java index 151f42a..ef6bc18 100644 --- a/src/main/java/com/educare/unitylend/controller/TransactionController.java +++ b/src/main/java/com/educare/unitylend/controller/TransactionController.java @@ -1,13 +1,36 @@ package com.educare.unitylend.controller; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Slf4j -@AllArgsConstructor -@RestController -@RequestMapping("/transaction") +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.Transaction; +import com.educare.unitylend.model.User; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; + +import java.time.LocalDate; +import java.util.List; + public class TransactionController extends BaseController{ + + ResponseEntity> getTransactionsBySender(@PathVariable String userId) throws ControllerException{ + return null; + }; + + ResponseEntity> getTransactionsBetween(@PathVariable String senderId, @PathVariable String receiverId) throws ControllerException + { + return null; + }; + ResponseEntity> getAllTransactions() throws ControllerException + { + return null; + }; + + ResponseEntity> getTransactionsByDate(@PathVariable LocalDate date) throws ControllerException + { + return null; + }; + ResponseEntity initiateTransaction( @RequestBody Transaction transaction) throws ControllerException + { + return null; + }; } diff --git a/src/main/java/com/educare/unitylend/controller/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index 78723c7..47374d8 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -6,16 +6,40 @@ import com.educare.unitylend.service.UserService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; - @Slf4j @AllArgsConstructor @RestController @RequestMapping("/user") -public class UserController extends BaseController{ +public class UserController { + + + + ResponseEntity> getAllUsers() throws ServiceException { + return null; + } + + ResponseEntity updateUser(User user) throws ServiceException { + return null; + } + + ResponseEntity createUser(User user) throws ServiceException { + return null; + } + + ResponseEntity getUserById(String userId) throws ServiceException { + return null; + } + + ResponseEntity deleteUser(String userId) throws ServiceException { + return null; + } } + + diff --git a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java index b09e047..420ead7 100644 --- a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java +++ b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java @@ -1,5 +1,25 @@ package com.educare.unitylend.service; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.BorrowRequest; +import com.educare.unitylend.model.Status; + +import java.util.List; + public interface BorrowRequestService { + // List getRequestedCommunitiesByUserId(String userId) throws ServiceException; + List getAllBorrowRequests() throws ServiceException; + List getBorrowRequestForUserId(String userId) throws ServiceException; + boolean createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException; + + List getBorrowRequestForCommunity(List communityId ) throws ServiceException; + + + boolean updateEMIDefaults() throws ServiceException; + + boolean updateBorrowRequestStatus(Status status) throws ServiceException; + + // boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException; + } \ No newline at end of file diff --git a/src/main/java/com/educare/unitylend/service/TransactionService.java b/src/main/java/com/educare/unitylend/service/TransactionService.java index 3b35de7..4c46fe2 100644 --- a/src/main/java/com/educare/unitylend/service/TransactionService.java +++ b/src/main/java/com/educare/unitylend/service/TransactionService.java @@ -1,4 +1,22 @@ package com.educare.unitylend.service; +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.Transaction; +import com.educare.unitylend.model.User; + +import java.time.LocalDate; +import java.util.List; public interface TransactionService { + + List getTransactionsBySender(User sender) throws ControllerException; + + List getTransactionsBetween(User sender, User receiver) throws ControllerException; + + List getAllTransactions() throws ControllerException; + + List getTransactionsByDate(LocalDate date) throws ControllerException; + + boolean initiateTransaction(Transaction transaction) throws ControllerException; + } diff --git a/src/main/java/com/educare/unitylend/service/UserService.java b/src/main/java/com/educare/unitylend/service/UserService.java index 77adf74..a2840c7 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -2,8 +2,19 @@ import com.educare.unitylend.Exception.ServiceException; import com.educare.unitylend.model.User; + import java.util.List; public interface UserService { + + List getAllUsers() throws ServiceException; + + boolean updateUserDetails(User user) throws ServiceException; + // boolean markUserAsInactive(String userId) throws ServiceException; + boolean createUser(User user) throws ServiceException; + + User getUserByUserId(String userId) throws ServiceException; + + boolean deleteUser(String userId) throws ServiceException; } diff --git a/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java index 722a3bb..128408e 100644 --- a/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java @@ -1,12 +1,86 @@ package com.educare.unitylend.service.impl; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.BorrowRequest; +import com.educare.unitylend.model.Status; import com.educare.unitylend.service.BorrowRequestService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @AllArgsConstructor @Service public class BorrowRequestServiceImpl implements BorrowRequestService { + @Override + public List getAllBorrowRequests() throws ServiceException { + return null; + } + + @Override + public List getBorrowRequestForUserId(String userId) throws ServiceException { + return null; + } + + @Override + public boolean createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException { + return false; + } + + @Override + public List getBorrowRequestForCommunity(List communityId) throws ServiceException { + return null; + } + + + @Override + public boolean updateEMIDefaults() throws ServiceException { + return false; + } + + @Override + public boolean updateBorrowRequestStatus(Status status) throws ServiceException { + return false; + } + +// private UserRepository userRepository; +// private BorrowRequestRepository borrowRequestRepository; +// public List getRequestedCommunitiesByUserId(String userId) throws ServiceException{ +// List communities=borrowRequestRepository.getBorrowRequestByUserId(userId); +// System.out.println(communities); +// return communities; +// } +// +// public void createBorrowRequest(BorrowRequest borrowRequest) { +// borrowRequestRepository.createBorrowRequest(borrowRequest); +// } +// 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); +// BigDecimal loanTenureMonths = new BigDecimal(borrowRequest.getReturnPeriod()).multiply(new BigDecimal("30.44")); +// double pow = Math.pow(1 + monthlyInterestRate.doubleValue(), loanTenureMonths.doubleValue()); +// BigDecimal emiNumerator = borrowRequest.getTargetAmount() +// .multiply(new BigDecimal(pow)).multiply(new BigDecimal(50)); +// +// +// BigDecimal emiDenominator = new BigDecimal(pow - 1); +// +// BigDecimal emi = emiNumerator.divide(emiDenominator, 2, RoundingMode.HALF_UP); +// // BigDecimal emi =borrowRequest.getTargetAmount().divide(new BigDecimal(borrowRequest.getReturnPeriod())); +// if (emi.compareTo(new BigDecimal(userRepository.getIncome(userId)).divide(new BigDecimal(2), 2, RoundingMode.HALF_UP)) <0) { +// return false; +// } +// return true; +// +// } catch (Exception e) { +// throw new ServiceException("Error in calculating EMI", e); +// } +// } + + + } + diff --git a/src/main/java/com/educare/unitylend/service/impl/TransactionServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/TransactionServiceImpl.java index 4c0d0e4..9b41d29 100644 --- a/src/main/java/com/educare/unitylend/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/TransactionServiceImpl.java @@ -1,12 +1,43 @@ package com.educare.unitylend.service.impl; +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.Transaction; +import com.educare.unitylend.model.User; import com.educare.unitylend.service.TransactionService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.util.List; + @Slf4j @AllArgsConstructor @Service public class TransactionServiceImpl implements TransactionService { + @Override + public List getTransactionsBySender(User sender) throws ControllerException { + return null; + } + + @Override + public List getTransactionsBetween(User sender, User receiver) throws ControllerException { + return null; + } + + @Override + public List getAllTransactions() throws ControllerException { + return null; + } + + @Override + public List getTransactionsByDate(LocalDate date) throws ControllerException { + return null; + } + + @Override + public boolean initiateTransaction(Transaction transaction) throws ControllerException { + return false; + } } diff --git a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java index 9be3d0a..854bf1b 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -1,12 +1,167 @@ package com.educare.unitylend.service.impl; +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.CommunityRepository; +import com.educare.unitylend.dao.UserRepository; +import com.educare.unitylend.model.User; import com.educare.unitylend.service.UserService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Slf4j @AllArgsConstructor @Service public class UserServiceImpl implements UserService { + @Override + public List getAllUsers() throws ServiceException { + return null; + } + + @Override + public boolean updateUserDetails(User user) throws ServiceException { + return false; + } + + @Override + public boolean createUser(User user) throws ServiceException { + return false; + } + + @Override + public User getUserByUserId(String userId) throws ServiceException { + return null; + } + + @Override + public boolean deleteUser(String userId) throws ServiceException { + return false; + } + + +// private UserRepository userRepository; +// private CommunityRepository communityRepository; +// private UserCommunityController userCommunityController; +// private UserCommunityRepository userCommunityRepository; +// +// @Override +// public List getUsers() throws ServiceException { +// try { +// List userList = userRepository.getAllUsers(); +// log.info("userList ", userList); +// return userList; +// } catch (Exception e) { +// log.error("Error encountered during user fetching operation"); +// throw new ServiceException("Error encountered during user fetch operation", e); +// } +// } +// +// +// @Override +// public User getUserByUserId(String userId) throws ServiceException { +// try { +// User user = userRepository.getUserForUserId(userId); +// return user; +// } catch (Exception e) { +// log.error("Error encountered during user fetch operation"); +// throw new ServiceException("Error encountered during user fetch operation", e); +// } +// } +// +// +// public void createUser(User newUser) throws ServiceException { +// List matchingCommontags = findMatchingCommontags(newUser); +// try { +// // Add any validation logic if needed before saving to the database +// for (String tag : matchingCommontags) { +// if (!communityRepository.existsByCommontag(tag)) { +// +// communityRepository.createCommunityUsingStrings(tag, tag); +// } +// +// } +// +// userRepository.createUser(newUser); +// newUser.setUserid(userRepository.settingID(newUser.getEmail())); +// // log.info("addeddd!!!!", newUser.getIncome()); +// newUser.setBorrowingLimit(newUser.getIncome() / 2); +// +// // log.info("addeddd!!!!", newUser.getBorrowingLimit()); +// +// String collegeUni = newUser.getCollegeuniversity(); +// String office = newUser.getOfficename(); +// String locality = newUser.getLocality(); +// if (collegeUni != null) { +// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(collegeUni)); +// } +// if (office != null) { +// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(office)); +// } +// if (locality != null) { +// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(locality)); +// } +// +// +// } catch (Exception e) { +// log.error("Error encountered during user creation operation"); +// throw new ServiceException("Error encountered during user creation operation", e); +// } +// } +// private List findMatchingCommontags(User user) { +// List matchingCommontags = new ArrayList<>(); +// String officenameCommontag=null; +// String collegeuniversityCommontag=null; +// String localityCommontag=null; +// +// // Check if officename, collegeuniversity, or locality exists in the Community table as commontag +// if(user.getOfficename()!=null) +// officenameCommontag = communityRepository.findByCommontag(user.getOfficename()); +// if(user.getCollegeuniversity()!=null) +// collegeuniversityCommontag = communityRepository.findByCommontag(user.getCollegeuniversity()); +// if(user.getLocality()!=null) +// localityCommontag = communityRepository.findByCommontag(user.getLocality()); +// +// // Add non-null commontags to the list +// if (officenameCommontag == null && user.getOfficename()!=null ) { +// matchingCommontags.add(user.getOfficename()); +// } +// if (collegeuniversityCommontag == null && user.getCollegeuniversity()!=null) { +// matchingCommontags.add(user.getCollegeuniversity()); +// } +// if (localityCommontag == null && user.getLocality()!=null) { +// matchingCommontags.add(user.getLocality()); +// } +// +// return matchingCommontags; +// } +// +// public void updateUser(User user) throws ServiceException { +// try { +// System.out.println(user); +// userRepository.updateUser(user); +// +// } catch (Exception e) { +// log.error("Error encountered during user fetching operation"); +// throw new ServiceException("Error encountered during user fetch operation", e); +// } +// } +// +// public boolean markUserAsInactive(String userId) throws ServiceException { +// try { +// User user = userRepository.getUserForUserId(userId); +// if (user != null) { +// user.setActive(false); +// userRepository.inactivatingUser(user); +// return true; +// } else { +// return false; +// } +// } catch (Exception e) { +// throw new ServiceException("Error marking user as inactive", e); +// } +// } + } diff --git a/src/main/java/com/educare/unitylend/service/implOld/BorrowRequestServiceImpl.java b/src/main/java/com/educare/unitylend/service/implOld/BorrowRequestServiceImpl.java index 5875ab2..68292f0 100644 --- a/src/main/java/com/educare/unitylend/service/implOld/BorrowRequestServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/implOld/BorrowRequestServiceImpl.java @@ -1,141 +1,141 @@ -package com.educare.unitylend.service.implOld; - -import com.educare.unitylend.Exception.ServiceException; -import com.educare.unitylend.dao.BorrowRequestCommunityMapRepository; -import com.educare.unitylend.dao.BorrowRequestRepository; -import com.educare.unitylend.dao.UserRepository; -import com.educare.unitylend.model.BorrowRequest; -import com.educare.unitylend.model.Community; -import com.educare.unitylend.model.User; -import com.educare.unitylend.service.BorrowRequestService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@AllArgsConstructor -@Service -public class BorrowRequestServiceImpl implements BorrowRequestService { - private UserRepository userRepository; - private BorrowRequestRepository borrowRequestRepository; - private BorrowRequestCommunityMapRepository borrowRequestCommunityRepository; - - @Override - public List getCommunitiesForWhichBorrowRequestRaisedByUser(String userId) throws ServiceException { - - try { - ListborrowRequestListByUser=borrowRequestRepository.getBorrowRequestsByUserId(userId); - Listcommunities=new ArrayList<>(); - - for(BorrowRequest request:borrowRequestListByUser){ - ListcommunityList=borrowRequestCommunityRepository.getCommunitiesByRequestId(request.getRequestId()); - for(Community community:communityList){ - if(!communities.contains(community)){ - communities.add(community); - } - } - } - return communities; - } catch (Exception e) { - log.error("Error while getting communities where given user has raised request"); - throw new ServiceException("Error while getting communities where given user has raised request", e); - } - } - - @Override - public void createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException { - - try { - borrowRequestRepository.createBorrowRequest(borrowRequest); - - List communityIds = borrowRequest.getCommunityIds(); - String requestId = borrowRequest.getRequestId(); - - mapBorrowRequestToCommunity(requestId, communityIds); - } catch (Exception e) { - log.error("Error while creating borrow request"); - throw new ServiceException("Error while creating borrow request", e); - } - - } - - @Override - public void mapBorrowRequestToCommunity(String requestId, List CommunityIds) { - for (String communityId : CommunityIds) { - borrowRequestCommunityRepository.createBorrowRequestCommunityMapping(requestId, communityId); - } - } - - @Override - public void mapBorrowRequestToCommunity(String requestId, String communityId) { - borrowRequestCommunityRepository.createBorrowRequestCommunityMapping(requestId, communityId); - } - - @Override - public boolean validateBorrowRequest(BorrowRequest borrowRequest) throws ServiceException { - - try { - String borrowerId=borrowRequest.getBorrower().getUserId(); - User borrower = userRepository.getUserForUserId(borrowerId); - Integer returnPeriod = borrowRequest.getReturnPeriod(); - BigDecimal returnPeriodInMonths = daysToMonths(returnPeriod); - BigDecimal requestedAmount = borrowRequest.getRequestedAmount(); - BigDecimal monthlyInterestRate = borrowRequest.getMonthlyInterestRate(); - - BigDecimal monthlyEMI = calculateMonthlyEMI(requestedAmount, monthlyInterestRate, returnPeriodInMonths); - Integer income = borrower.getIncome(); - - return isMonthlyEMIAffordable(income, monthlyEMI); - } catch (Exception e) { - log.error("Error while validating the borrow request"); - throw new ServiceException("Error while validating the borrow request", e); - } - - } - - @Override - public List getAllBorrowRequests() throws ServiceException{ - try{ - return borrowRequestRepository.getAllBorrowRequests(); - } - catch (Exception e){ - log.error("Error encountered while getting all borrow requests"); - throw new ServiceException("Error encountered while getting all borrow requests",e); - } - } - - @Override - public List getBorrowRequestsByUserId(String userId) throws ServiceException{ - try { - List borrowRequestList = borrowRequestRepository.getBorrowRequestsByUserId(userId); - return borrowRequestList; - } catch (Exception e) { - log.error("Error encountered during getting requests by user id"); - throw new ServiceException("Error encountered during getting requests by user id", e); - } - } - - - public BigDecimal calculateMonthlyEMI(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal timeInMonths) { - - BigDecimal numerator = principal.multiply(BigDecimal.ONE.add(monthlyInterestRate.multiply(timeInMonths))); - BigDecimal monthlyEMI = numerator.divide(timeInMonths, 2, BigDecimal.ROUND_HALF_UP); - - return monthlyEMI; - } - - public boolean isMonthlyEMIAffordable(Integer income, BigDecimal monthlyEMI) { - BigDecimal halfIncome = BigDecimal.valueOf(income / 2); - return halfIncome.compareTo(monthlyEMI) >= 0; - } - - public BigDecimal daysToMonths(Integer days) { - return BigDecimal.valueOf(days).divide(BigDecimal.valueOf(30), 2, RoundingMode.HALF_UP); - } - -} \ No newline at end of file +//package com.educare.unitylend.service.implOld; +// +//import com.educare.unitylend.Exception.ServiceException; +//import com.educare.unitylend.dao.BorrowRequestCommunityMapRepository; +//import com.educare.unitylend.dao.BorrowRequestRepository; +//import com.educare.unitylend.dao.UserRepository; +//import com.educare.unitylend.model.BorrowRequest; +//import com.educare.unitylend.model.Community; +//import com.educare.unitylend.model.User; +//import com.educare.unitylend.service.BorrowRequestService; +//import lombok.AllArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Service; +// +//import java.math.BigDecimal; +//import java.math.RoundingMode; +//import java.util.ArrayList; +//import java.util.List; +// +//@Slf4j +//@AllArgsConstructor +//@Service +//public class BorrowRequestServiceImpl implements BorrowRequestService { +// private UserRepository userRepository; +// private BorrowRequestRepository borrowRequestRepository; +// private BorrowRequestCommunityMapRepository borrowRequestCommunityRepository; +// +// @Override +// public List getCommunitiesForWhichBorrowRequestRaisedByUser(String userId) throws ServiceException { +// +// try { +// ListborrowRequestListByUser=borrowRequestRepository.getBorrowRequestsByUserId(userId); +// Listcommunities=new ArrayList<>(); +// +// for(BorrowRequest request:borrowRequestListByUser){ +// ListcommunityList=borrowRequestCommunityRepository.getCommunitiesByRequestId(request.getRequestId()); +// for(Community community:communityList){ +// if(!communities.contains(community)){ +// communities.add(community); +// } +// } +// } +// return communities; +// } catch (Exception e) { +// log.error("Error while getting communities where given user has raised request"); +// throw new ServiceException("Error while getting communities where given user has raised request", e); +// } +// } +// +// @Override +// public void createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException { +// +// try { +// borrowRequestRepository.createBorrowRequest(borrowRequest); +// +// List communityIds = borrowRequest.getCommunityIds(); +// String requestId = borrowRequest.getRequestId(); +// +// mapBorrowRequestToCommunity(requestId, communityIds); +// } catch (Exception e) { +// log.error("Error while creating borrow request"); +// throw new ServiceException("Error while creating borrow request", e); +// } +// +// } +// +// @Override +// public void mapBorrowRequestToCommunity(String requestId, List CommunityIds) { +// for (String communityId : CommunityIds) { +// borrowRequestCommunityRepository.createBorrowRequestCommunityMapping(requestId, communityId); +// } +// } +// +// @Override +// public void mapBorrowRequestToCommunity(String requestId, String communityId) { +// borrowRequestCommunityRepository.createBorrowRequestCommunityMapping(requestId, communityId); +// } +// +// @Override +// public boolean validateBorrowRequest(BorrowRequest borrowRequest) throws ServiceException { +// +// try { +// String borrowerId=borrowRequest.getBorrower().getUserId(); +// User borrower = userRepository.getUserForUserId(borrowerId); +// Integer returnPeriod = borrowRequest.getReturnPeriod(); +// BigDecimal returnPeriodInMonths = daysToMonths(returnPeriod); +// BigDecimal requestedAmount = borrowRequest.getRequestedAmount(); +// BigDecimal monthlyInterestRate = borrowRequest.getMonthlyInterestRate(); +// +// BigDecimal monthlyEMI = calculateMonthlyEMI(requestedAmount, monthlyInterestRate, returnPeriodInMonths); +// Integer income = borrower.getIncome(); +// +// return isMonthlyEMIAffordable(income, monthlyEMI); +// } catch (Exception e) { +// log.error("Error while validating the borrow request"); +// throw new ServiceException("Error while validating the borrow request", e); +// } +// +// } +// +// @Override +// public List getAllBorrowRequests() throws ServiceException{ +// try{ +// return borrowRequestRepository.getAllBorrowRequests(); +// } +// catch (Exception e){ +// log.error("Error encountered while getting all borrow requests"); +// throw new ServiceException("Error encountered while getting all borrow requests",e); +// } +// } +// +// @Override +// public List getBorrowRequestsByUserId(String userId) throws ServiceException{ +// try { +// List borrowRequestList = borrowRequestRepository.getBorrowRequestsByUserId(userId); +// return borrowRequestList; +// } catch (Exception e) { +// log.error("Error encountered during getting requests by user id"); +// throw new ServiceException("Error encountered during getting requests by user id", e); +// } +// } +// +// +// public BigDecimal calculateMonthlyEMI(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal timeInMonths) { +// +// BigDecimal numerator = principal.multiply(BigDecimal.ONE.add(monthlyInterestRate.multiply(timeInMonths))); +// BigDecimal monthlyEMI = numerator.divide(timeInMonths, 2, BigDecimal.ROUND_HALF_UP); +// +// return monthlyEMI; +// } +// +// public boolean isMonthlyEMIAffordable(Integer income, BigDecimal monthlyEMI) { +// BigDecimal halfIncome = BigDecimal.valueOf(income / 2); +// return halfIncome.compareTo(monthlyEMI) >= 0; +// } +// +// public BigDecimal daysToMonths(Integer days) { +// return BigDecimal.valueOf(days).divide(BigDecimal.valueOf(30), 2, RoundingMode.HALF_UP); +// } +// +//} \ No newline at end of file diff --git a/src/main/java/com/educare/unitylend/service/implOld/UserServiceImpl.java b/src/main/java/com/educare/unitylend/service/implOld/UserServiceImpl.java index 25672cf..3fad65d 100644 --- a/src/main/java/com/educare/unitylend/service/implOld/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/implOld/UserServiceImpl.java @@ -1,126 +1,126 @@ -package com.educare.unitylend.service.implOld; - -import com.educare.unitylend.Exception.ServiceException; -import com.educare.unitylend.dao.CommunityRepository; -import com.educare.unitylend.dao.UserCommunityMapRepository; -import com.educare.unitylend.dao.UserRepository; -import com.educare.unitylend.model.User; -import com.educare.unitylend.service.UserService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@AllArgsConstructor -@Service -public class UserServiceImpl implements UserService { - - private UserRepository userRepository; - private CommunityRepository communityRepository; - private UserCommunityMapRepository userCommunityMapRepository; - - @Override - public List getUsers() throws ServiceException { - try { - List userList = userRepository.getAllUsers(); - log.info("userList ", userList); - return userList; - } catch (Exception e) { - log.error("Error encountered during user fetching operation"); - throw new ServiceException("Error encountered during user fetch operation", e); - } - } - - - @Override - public User getUserByUserId(String userId) throws ServiceException { - try { - User user = userRepository.getUserForUserId(userId); - return user; - } catch (Exception e) { - log.error("Error encountered while getting user by user id"); - throw new ServiceException("Error encountered while getting user by user id", e); - } - } - - - public void createUser(User newUser) throws ServiceException { - try { - List commonTags = new ArrayList<>(); - if (newUser.getOfficeName() != null) commonTags.add(newUser.getOfficeName()); - if (newUser.getCollegeUniversity() != null) commonTags.add(newUser.getCollegeUniversity()); - if (newUser.getLocality() != null) commonTags.add(newUser.getLocality()); - - for (String commonTag : commonTags) { - if (!communityRepository.existsByCommontag(commonTag)) { - log.info("Creating community::", commonTag); - communityRepository.createCommunityUsingStrings(commonTag, commonTag); - } - } - - userRepository.createUser(newUser); - newUser.setUserId(userRepository.settingID(newUser.getEmail())); - newUser.setBorrowingLimit(newUser.getIncome() / 2); - mapUserToCommunity(newUser.getUserId(), commonTags); - } catch (Exception e) { - log.error("Error encountered during user creation operation"); - throw new ServiceException("Error encountered during user creation operation", e); - } - } - - private void mapUserToCommunity(String userId, List commonTags) { - - for (String commonTag : commonTags) { - userCommunityMapRepository.createUserCommunityMapping(userId, communityRepository.getCommunityIdByName(commonTag)); - } - } - - private void mapUserToCommunity(String userId, String commonTag) { - userCommunityMapRepository.createUserCommunityMapping(userId, communityRepository.getCommunityIdByName(commonTag)); - } - - - public void updateUser(User user, String userId) throws ServiceException { - List updatedCommunities; - String[] communityName = new String[3]; - try { - userCommunityMapRepository.deletePrevData(userId); - userRepository.updateUser(user); - updatedCommunities = userRepository.findCommunitiesByUserId(userId); - for (String community : updatedCommunities) { - communityName = community.split(", "); - } - for (int i = 0; i < 3; i++) { - if (!communityRepository.existsByCommontag(communityName[i])) { - communityRepository.createCommunityUsingStrings(communityName[i], communityName[i]); - mapUserToCommunity(user.getUserId(), communityName[i]); - } - } - user.setBorrowingLimit(user.getIncome() / 2); - - - } catch (Exception e) { - log.error("Error encountered during user fetching operation"); - throw new ServiceException("Error encountered during user fetch operation", e); - } - } - - public boolean markUserAsInactive(String userId) throws ServiceException { - try { - User user = userRepository.getUserForUserId(userId); - if (user != null) { - user.setActive(false); - userRepository.inactivatingUser(user); - return true; - } else { - return false; - } - } catch (Exception e) { - throw new ServiceException("Error marking user as inactive", e); - } - } - -} +//package com.educare.unitylend.service.implOld; +// +//import com.educare.unitylend.Exception.ServiceException; +//import com.educare.unitylend.dao.CommunityRepository; +//import com.educare.unitylend.dao.UserCommunityMapRepository; +//import com.educare.unitylend.dao.UserRepository; +//import com.educare.unitylend.model.User; +//import com.educare.unitylend.service.UserService; +//import lombok.AllArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Service; +// +//import java.util.ArrayList; +//import java.util.List; +// +//@Slf4j +//@AllArgsConstructor +//@Service +//public class UserServiceImpl implements UserService { +// +// private UserRepository userRepository; +// private CommunityRepository communityRepository; +// private UserCommunityMapRepository userCommunityMapRepository; +// +// @Override +// public List getUsers() throws ServiceException { +// try { +// List userList = userRepository.getAllUsers(); +// log.info("userList ", userList); +// return userList; +// } catch (Exception e) { +// log.error("Error encountered during user fetching operation"); +// throw new ServiceException("Error encountered during user fetch operation", e); +// } +// } +// +// +// @Override +// public User getUserByUserId(String userId) throws ServiceException { +// try { +// User user = userRepository.getUserForUserId(userId); +// return user; +// } catch (Exception e) { +// log.error("Error encountered while getting user by user id"); +// throw new ServiceException("Error encountered while getting user by user id", e); +// } +// } +// +// +// public void createUser(User newUser) throws ServiceException { +// try { +// List commonTags = new ArrayList<>(); +// if (newUser.getOfficeName() != null) commonTags.add(newUser.getOfficeName()); +// if (newUser.getCollegeUniversity() != null) commonTags.add(newUser.getCollegeUniversity()); +// if (newUser.getLocality() != null) commonTags.add(newUser.getLocality()); +// +// for (String commonTag : commonTags) { +// if (!communityRepository.existsByCommontag(commonTag)) { +// log.info("Creating community::", commonTag); +// communityRepository.createCommunityUsingStrings(commonTag, commonTag); +// } +// } +// +// userRepository.createUser(newUser); +// newUser.setUserId(userRepository.settingID(newUser.getEmail())); +// newUser.setBorrowingLimit(newUser.getIncome() / 2); +// mapUserToCommunity(newUser.getUserId(), commonTags); +// } catch (Exception e) { +// log.error("Error encountered during user creation operation"); +// throw new ServiceException("Error encountered during user creation operation", e); +// } +// } +// +// private void mapUserToCommunity(String userId, List commonTags) { +// +// for (String commonTag : commonTags) { +// userCommunityMapRepository.createUserCommunityMapping(userId, communityRepository.getCommunityIdByName(commonTag)); +// } +// } +// +// private void mapUserToCommunity(String userId, String commonTag) { +// userCommunityMapRepository.createUserCommunityMapping(userId, communityRepository.getCommunityIdByName(commonTag)); +// } +// +// +// public void updateUser(User user, String userId) throws ServiceException { +// List updatedCommunities; +// String[] communityName = new String[3]; +// try { +// userCommunityMapRepository.deletePrevData(userId); +// userRepository.updateUser(user); +// updatedCommunities = userRepository.findCommunitiesByUserId(userId); +// for (String community : updatedCommunities) { +// communityName = community.split(", "); +// } +// for (int i = 0; i < 3; i++) { +// if (!communityRepository.existsByCommontag(communityName[i])) { +// communityRepository.createCommunityUsingStrings(communityName[i], communityName[i]); +// mapUserToCommunity(user.getUserId(), communityName[i]); +// } +// } +// user.setBorrowingLimit(user.getIncome() / 2); +// +// +// } catch (Exception e) { +// log.error("Error encountered during user fetching operation"); +// throw new ServiceException("Error encountered during user fetch operation", e); +// } +// } +// +// public boolean markUserAsInactive(String userId) throws ServiceException { +// try { +// User user = userRepository.getUserForUserId(userId); +// if (user != null) { +// user.setActive(false); +// userRepository.inactivatingUser(user); +// return true; +// } else { +// return false; +// } +// } catch (Exception e) { +// throw new ServiceException("Error marking user as inactive", e); +// } +// } +// +//}