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
192 changes: 96 additions & 96 deletions pom.xml
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>-->
<!-- &lt;!&ndash; Changed the scope to provided to use the dependency at runtime for tomcat (external)&ndash;&gt;-->
<!-- <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>
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}")
Copy link
Collaborator

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.

Copy link
Collaborator

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.

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 src/main/java/com/educare/unitylend/dao/BorrowReqRepository.java
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 src/main/java/com/educare/unitylend/service/BorrowReqService.java
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;
}
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);
}
}
}