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
Original file line number Diff line number Diff line change
@@ -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{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the methods throw ControllerException, not ServiceException

}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper annotations for Parameters and Request Body


ResponseEntity<List<BorrowRequest>> getAllBorrowRequests() throws ServiceException {
return null;
}

ResponseEntity<List<BorrowRequest>> getBorrowRequestForUserId(String userId) throws ServiceException {
return null;
}

ResponseEntity<Void> createBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ServiceException {
Copy link
Copy Markdown
Collaborator

@SURABHI2003 SURABHI2003 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make return type ResponseEntity<Boolean>

return null;
}

ResponseEntity<List<BorrowRequest>> getBorrowRequestForCommunity(@RequestParam List<String> communityId) throws ServiceException {
return null;
}

ResponseEntity<Void> updateEMIDefaults() throws ServiceException {
Copy link
Copy Markdown
Collaborator

@SURABHI2003 SURABHI2003 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make return type ResponseEntity<Boolean>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove updateEMIdefaults and updateBorrowRequestStatus

return null;
}

ResponseEntity<Void> updateBorrowRequestStatus(@RequestBody Status status) throws ServiceException {
Copy link
Copy Markdown
Collaborator

@SURABHI2003 SURABHI2003 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make return type ResponseEntity<Boolean>

return null;
}
}



Original file line number Diff line number Diff line change
@@ -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{

Copy link
Copy Markdown
Collaborator

@SURABHI2003 SURABHI2003 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove semi-colons

ResponseEntity<List<Transaction>> getTransactionsBySender(@PathVariable String userId) throws ControllerException{
return null;
};

ResponseEntity<List<Transaction>> getTransactionsBetween(@PathVariable String senderId, @PathVariable String receiverId) throws ControllerException
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to a better name

{
return null;
};
ResponseEntity<List<Transaction>> getAllTransactions() throws ControllerException
{
return null;
};

ResponseEntity<List<Transaction>> getTransactionsByDate(@PathVariable LocalDate date) throws ControllerException
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTransactionsBetweenDate(start,end)

{
return null;
};
ResponseEntity<Transaction> initiateTransaction( @RequestBody Transaction transaction) throws ControllerException
{
return null;
};
}
28 changes: 26 additions & 2 deletions src/main/java/com/educare/unitylend/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Param and RequestBody Annotations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the methods throw ControllerException, not ServiceException

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this class extend BaseController



ResponseEntity<List<User>> getAllUsers() throws ServiceException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw controller exception

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments for administration purposes

return null;
}

ResponseEntity<User> updateUser(User user) throws ServiceException {
return null;
}

ResponseEntity<User> createUser(User user) throws ServiceException {
return null;
}

ResponseEntity<User> getUserById(String userId) throws ServiceException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to getUserForUserId

return null;
}

ResponseEntity<Void> deleteUser(String userId) throws ServiceException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make return type ResponseEntity<Boolean>

return null;
}
}


Original file line number Diff line number Diff line change
@@ -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<String> getRequestedCommunitiesByUserId(String userId) throws ServiceException;
List<BorrowRequest> getAllBorrowRequests() throws ServiceException;
List<BorrowRequest> getBorrowRequestForUserId(String userId) throws ServiceException;
boolean createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException;

List<BorrowRequest> getBorrowRequestForCommunity(List <String> communityId ) throws ServiceException;


boolean updateEMIDefaults() throws ServiceException;

boolean updateBorrowRequestStatus(Status status) throws ServiceException;

// boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException;

}
Original file line number Diff line number Diff line change
@@ -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<Transaction> getTransactionsBySender(User sender) throws ControllerException;

List<Transaction> getTransactionsBetween(User sender, User receiver) throws ControllerException;

List<Transaction> getAllTransactions() throws ControllerException;

List<Transaction> getTransactionsByDate(LocalDate date) throws ControllerException;

boolean initiateTransaction(Transaction transaction) throws ControllerException;

}
11 changes: 11 additions & 0 deletions src/main/java/com/educare/unitylend/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.model.User;

import java.util.List;

public interface UserService {


List<User> 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;
}
Original file line number Diff line number Diff line change
@@ -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<BorrowRequest> getAllBorrowRequests() throws ServiceException {
return null;
}

@Override
public List<BorrowRequest> getBorrowRequestForUserId(String userId) throws ServiceException {
return null;
}

@Override
public boolean createBorrowRequest(BorrowRequest borrowRequest) throws ServiceException {
return false;
}

@Override
public List<BorrowRequest> getBorrowRequestForCommunity(List <String> 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<String> getRequestedCommunitiesByUserId(String userId) throws ServiceException{
// List<String> 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);
// }
// }



}

Original file line number Diff line number Diff line change
@@ -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<Transaction> getTransactionsBySender(User sender) throws ControllerException {
return null;
}

@Override
public List<Transaction> getTransactionsBetween(User sender, User receiver) throws ControllerException {
return null;
}

@Override
public List<Transaction> getAllTransactions() throws ControllerException {
return null;
}

@Override
public List<Transaction> getTransactionsByDate(LocalDate date) throws ControllerException {
return null;
}

@Override
public boolean initiateTransaction(Transaction transaction) throws ControllerException {
return false;
}
}
Loading