diff --git a/.gitignore b/.gitignore index 2f0833d..edb4cf8 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ build/ logs/ .nfs* + + diff --git a/pom.xml b/pom.xml index b95f6e6..8081919 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot @@ -43,7 +43,7 @@ org.springframework.boot spring-boot-starter-tomcat - provided + org.springframework.boot diff --git a/src/main/java/com/educare/unitylend/UnitylendApplication.java b/src/main/java/com/educare/unitylend/UnitylendApplication.java index 3090971..0964285 100644 --- a/src/main/java/com/educare/unitylend/UnitylendApplication.java +++ b/src/main/java/com/educare/unitylend/UnitylendApplication.java @@ -2,11 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; - @SpringBootApplication public class UnitylendApplication { public static void main(String[] args) { + SpringApplication.run(UnitylendApplication.class, args); } diff --git a/src/main/java/com/educare/unitylend/controller/CommunityController.java b/src/main/java/com/educare/unitylend/controller/CommunityController.java new file mode 100644 index 0000000..1a5c229 --- /dev/null +++ b/src/main/java/com/educare/unitylend/controller/CommunityController.java @@ -0,0 +1,56 @@ +package com.educare.unitylend.controller; + +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.Community; +import com.educare.unitylend.service.CommunityService; +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("/community") + +public class CommunityController extends BaseController { + CommunityService communityService; + + @GetMapping("all-communities") + public List getAllCommunities() throws ControllerException { + + try { + List communityList = communityService.getCommunities(); + return communityList; + } catch (Exception e) { + log.error("Error encountered in getting the users"); + throw new ControllerException("Error encountered in getting the users", e); + } + } + @GetMapping("get-community-by-tag") + public String getCommunityWithTag(@RequestParam String commonTag) throws ControllerException { + try { + String communityName = communityService.getCommunityName(commonTag); + return communityName; + } catch (Exception e) { + log.error("Error encountered in getting the community by tag"); + throw new ControllerException("Error encountered in getting the community by tag", e); + } + } + + + @PostMapping("/create-community") + public ResponseEntity createNewCommunity(@RequestBody Community community) throws ControllerException { + try { + communityService.createCommunity(community); + return ResponseEntity.ok("success!!!"); + } catch (Exception e) { + log.error("Error encountered in getting the users"); + throw new ControllerException("Error encountered in getting the users", e); + } + + } + +} diff --git a/src/main/java/com/educare/unitylend/controller/UserCommunityController.java b/src/main/java/com/educare/unitylend/controller/UserCommunityController.java new file mode 100644 index 0000000..a4b577f --- /dev/null +++ b/src/main/java/com/educare/unitylend/controller/UserCommunityController.java @@ -0,0 +1,32 @@ +package com.educare.unitylend.controller; + +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.User; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +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 { + + +// @GetMapping("all-users-community") + // public List getAllUsers() throws ControllerException { +// try { +// List userList = ; +// return userList; +// } catch (Exception e) { +// log.error("Error encountered in getting the users"); +// throw new ControllerException("Error encountered in getting the users", e); +// } + // } + + +} diff --git a/src/main/java/com/educare/unitylend/controller/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index b0406b4..afc9b46 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -1,14 +1,12 @@ package com.educare.unitylend.controller; import com.educare.unitylend.Exception.ControllerException; -import com.educare.unitylend.Exception.ServiceException; import com.educare.unitylend.model.User; import com.educare.unitylend.service.UserService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -17,11 +15,9 @@ @RestController @RequestMapping("/user") public class UserController extends BaseController { - UserService userService; /** - * * @return List of all the available {@link User} * @throws ControllerException : Exception to be thrown from controller in case of any exception */ @@ -30,9 +26,41 @@ public List getAllUsers() throws ControllerException { try { List userList = userService.getUsers(); return userList; - } catch (ServiceException e) { + } catch (Exception e) { + log.error("Error encountered in getting the users"); + throw new ControllerException("Error encountered in getting the users", e); + } + } + + @PostMapping("/create-user") + public ResponseEntity createUser(@RequestBody User user) throws ControllerException { + // Create the user + try { + userService.createUser(user); + return ResponseEntity.ok("succcesss!!!"); + } catch (Exception e) { log.error("Error encountered in getting the users"); throw new ControllerException("Error encountered in getting the users", e); } + } + + @PutMapping("/{userId}") + public ResponseEntity updateUser(@PathVariable String userId, @RequestBody User updatedUser) throws ControllerException { + // Set the userId in the updatedUser object + updatedUser.setUserid(userId); + + // Validate and update the user + try { + userService.updateUser(updatedUser); + } catch (Exception e) { + log.error("Error encountered in getting the users"); + throw new ControllerException("Error encountered in getting the users", e); + } + + return ResponseEntity.ok("User updated successfully"); + } + } + + diff --git a/src/main/java/com/educare/unitylend/controller/WalletController.java b/src/main/java/com/educare/unitylend/controller/WalletController.java new file mode 100644 index 0000000..9256c49 --- /dev/null +++ b/src/main/java/com/educare/unitylend/controller/WalletController.java @@ -0,0 +1,83 @@ +package com.educare.unitylend.controller; + +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.Wallet; +import com.educare.unitylend.service.WalletService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +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 org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@AllArgsConstructor +@RestController +@RequestMapping("/wallet") +public class WalletController extends BaseController { + + WalletService walletService; + + /** + * @return List of all the available {@link Wallet} + * @throws ControllerException : Exception to be thrown from controller in case of any exception + */ + + @GetMapping("all-wallets") + public List getAllWallets() throws ControllerException { + try { + List walletList = walletService.getWallets(); + return walletList; + } catch (Exception e) { + log.error("Error encountered in getting the users"); + throw new ControllerException("Error encountered in getting the users", e); + } + } + + @GetMapping("/get-user-info/{userId}") + public Wallet getWalletInfo(@PathVariable String userId) throws ControllerException{ + + try { + return walletService.getWalletInfo(userId); + } catch (Exception e) { + log.error("Error encountered in getting the wallet info for the given user"); + throw new ControllerException("Error encountered in getting the wallet info for the given user", e); + } + } + + @GetMapping("get-wallet/{walletId}") + public Wallet getWalletById(@PathVariable String walletId) throws ControllerException { + try { + return walletService.getWalletById(walletId); + } catch (Exception e) { + log.error("Error in fetching desired wallet's details"); + throw new ControllerException("Error encountered in getting the wallet info for the given walletId", e); + } + } + + @PostMapping("/{walletId}/addAmount") + public ResponseEntity addAmountToWallet(@PathVariable String walletId, @RequestParam Float amount) throws ControllerException{ + try { + walletService.addAmountToWallet(walletId, amount); + return ResponseEntity.ok("Amount added successfully to wallet"); + } catch (Exception e) { + log.error("Error adding requested amount to wallet"); + throw new ControllerException("Error encountered while adding requested amount to wallet", e); + } + } + + @PostMapping("/{walletId}/debitAmount") + public ResponseEntity debitFromWallet(@PathVariable String walletId, @RequestParam Float amount) throws ControllerException{ + try { + walletService.debitFromWallet(walletId, amount); + return ResponseEntity.ok("Amount debited successfully from wallet"); + } catch (Exception e) { + log.error("Error debiting requested amount from wallet"); + throw new ControllerException("Error encountered while debiting requested amount from wallet", e); + } + } +} diff --git a/src/main/java/com/educare/unitylend/dao/CommunityRepository.java b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java new file mode 100644 index 0000000..c97d27e --- /dev/null +++ b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java @@ -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 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); +} diff --git a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java new file mode 100644 index 0000000..b3cec4e --- /dev/null +++ b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java @@ -0,0 +1,16 @@ +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.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface UserCommunityRepository { + @Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})") + void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId); + + +} diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 4c57b4b..18da957 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -1,10 +1,7 @@ package com.educare.unitylend.dao; import com.educare.unitylend.model.User; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; @@ -13,22 +10,34 @@ @Repository public interface UserRepository { - @Select(SELECT_USERS) - List getAllUsers(); - - @SelectProvider(type = UserRepository.class, method = "getUserForUserIdQuery") - User getUserForUserId(@Param("userId") String userId); - - static final String SELECT_USERS = "select user_id as userID, password, name from user_table"; - static String getUserForUserIdQuery(String userId){ StringBuilder sqlQueryBuilder = new StringBuilder(); - sqlQueryBuilder.append("select user_id as userID, password, name from user_table where 1=1 "); + sqlQueryBuilder.append("select userid as userID, password, name,email,dob,income,officename,collegeuniversity,locality from User where 1=1 "); if(userId != null){ sqlQueryBuilder.append(" and userId = %s".formatted(userId)); } return sqlQueryBuilder.toString(); } + + @Select("select * from tempuser") + List getAllUsers(); + + @SelectProvider(type = UserRepository.class, method = "getUserForUserIdQuery") + User getUserForUserId(@Param("UserId") String userId); + // static final List SELECT_USERS = "select password from User"; + + @Insert("INSERT INTO tempuser (userid, password, name,email,dob,income,officename,collegeuniversity,locality) VALUES (CAST(uuid_generate_v4() AS VARCHAR), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})") + void createUser(User user); + + + @Select("SELECT userid FROM tempuser WHERE email = #{email}") + String settingID(@Param("email") String email); + + + @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename},collegeuniversity=#{collegeuniversity} income = #{income} WHERE userid = #{userid}") + void updateUser(User user); + + } diff --git a/src/main/java/com/educare/unitylend/dao/WalletRepository.java b/src/main/java/com/educare/unitylend/dao/WalletRepository.java new file mode 100644 index 0000000..1a68519 --- /dev/null +++ b/src/main/java/com/educare/unitylend/dao/WalletRepository.java @@ -0,0 +1,44 @@ +package com.educare.unitylend.dao; + + +import com.educare.unitylend.model.User; +import com.educare.unitylend.model.Wallet; +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 org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; + + +import java.util.List; + + +@Mapper +@Repository +public interface WalletRepository { + + @Select("select * from wallet") + List getAllWallets(); + + + @Select("SELECT w.walletid, w.userid, w.balance FROM wallet w JOIN tempuser u ON w.userid = u.userid WHERE w.userid = #{userId}") + Wallet getWalletInfo(@Param("userId") String userId); + + + @Insert("INSERT INTO wallet (walletid, balance, userid) VALUES (uuid_generate_v4(), 0, #{userId})") + void generateWalletInTable(String userId); + + + @Select("SELECT u.* FROM tempuser u WHERE u.userid = (SELECT userid FROM wallet WHERE walletid = #{ex.walletid})") + User getUserIdWithWallet(@Param("ex") Wallet ex); + + + @Select("SELECT * FROM wallet WHERE walletid = #{walletid}") + Wallet getWalletById(@Param("walletid") String walletid); + + + @Update("UPDATE wallet SET balance = #{balance} WHERE walletid = #{walletid}") + void updateBalance(@Param("walletid") String walletid, @Param("balance") Float balance); +} diff --git a/src/main/java/com/educare/unitylend/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index d65f997..022b45e 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -4,14 +4,35 @@ import lombok.Data; import lombok.NoArgsConstructor; -import java.util.UUID; - @Data @NoArgsConstructor @AllArgsConstructor public class Community { - private UUID communityId; - private String communityName; + private String communityid; + private String communityname; + private String commontag; + + public String getCommunityid() { + return communityid; + } + + public void setCommunityid(String communityid) { + this.communityid = communityid; + } + + public String getCommunityname() { + return communityname; + } + + public void setCommunityname(String communityname) { + this.communityname = communityname; + } + public String getCommontag() { + return commontag; + } + public void setCommontag(String commontag) { + this.commontag = commontag; + } } diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index 73bebc7..f4a18f9 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -1,25 +1,107 @@ package com.educare.unitylend.model; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -import java.util.Date; -import java.util.UUID; +import java.time.LocalDate; @Data @NoArgsConstructor @AllArgsConstructor public class User { - private UUID userID; - private String password; - private String name; -// private String email; -// private Date dob; -// private Integer income; -// private String locality; -// private String college; -// private String company; -// private UUID walletID; + + @Getter @Setter private String userid; + @Getter @Setter private String password; + @Getter @Setter private String name; + @Getter @Setter private String email; + @Getter @Setter private LocalDate dob; + @Getter @Setter private Integer income; + @Getter @Setter private Integer borrowingLimit; + @Getter @Setter private String officename; + @Getter @Setter private String collegeuniversity; + @Getter @Setter private String locality; + + public Integer getIncome() { + return income; + } + + public String getOfficename() { + return officename; + } + + public void setOfficename(String officename) { + this.officename = officename; + } + + public String getCollegeuniversity() { + return collegeuniversity; + } + + public String getPassword() { + return password; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public LocalDate getDob() { + return dob; + } + + public void setCollegeuniversity(String collegeuniversity) { + this.collegeuniversity = collegeuniversity; + } + + public String getUserid() { + return userid; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setName(String name) { + this.name = name; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setDob(LocalDate dob) { + this.dob = dob; + } + + public void setUserid(String userid) { + this.userid = userid; + } + + public String getLocality() { + return locality; + } + + public void setLocality(String locality) { + this.locality = locality; + } + + public void setIncome(Integer income) { + // System.out.println(income); + this.income = income; + } + + public Integer getBorrowingLimit() { + return borrowingLimit; + } + + public void setBorrowingLimit(Integer borrowingLimit) { + this.borrowingLimit = borrowingLimit; + // System.out.println(borrowingLimit); + } + + } diff --git a/src/main/java/com/educare/unitylend/model/Wallet.java b/src/main/java/com/educare/unitylend/model/Wallet.java index da231a0..da14684 100644 --- a/src/main/java/com/educare/unitylend/model/Wallet.java +++ b/src/main/java/com/educare/unitylend/model/Wallet.java @@ -4,13 +4,36 @@ import lombok.Data; import lombok.NoArgsConstructor; -import java.util.UUID; @Data @NoArgsConstructor @AllArgsConstructor public class Wallet { - private UUID Wallet; - private UUID userId; - private Float Balance; + + private String walletid; + private User user; + private Float balance = 0f; + public String getWalletid() { + return walletid; + } + + public void setWalletid(String walletid) { + this.walletid = walletid; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Float getBalance() { + return balance; + } + + public void setBalance(Float balance) { + this.balance = balance; + } } diff --git a/src/main/java/com/educare/unitylend/service/CommunityService.java b/src/main/java/com/educare/unitylend/service/CommunityService.java new file mode 100644 index 0000000..f841e05 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/CommunityService.java @@ -0,0 +1,13 @@ +package com.educare.unitylend.service; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.Community; +import com.educare.unitylend.model.User; + +import java.util.List; + +public interface CommunityService { + List getCommunities() throws ServiceException; + String getCommunityName(String communityTag) throws ServiceException; + void createCommunity(Community community) throws ServiceException; +} diff --git a/src/main/java/com/educare/unitylend/service/UserService.java b/src/main/java/com/educare/unitylend/service/UserService.java index 627e07b..9776881 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -13,6 +13,9 @@ public interface UserService { */ List getUsers() throws ServiceException; + void updateUser(User user) throws ServiceException; + + void createUser(User user) throws ServiceException; /** * @param userId : Uniquely identifies a user * @return Object of {@link User} for the given parameter diff --git a/src/main/java/com/educare/unitylend/service/WalletService.java b/src/main/java/com/educare/unitylend/service/WalletService.java new file mode 100644 index 0000000..37e2419 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/WalletService.java @@ -0,0 +1,21 @@ +package com.educare.unitylend.service; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.Wallet; + +import java.util.List; + +public interface WalletService { + + Wallet getWalletInfo(String userId) throws ServiceException; + + void generateWallet(String userId) throws ServiceException; + + List getWallets() throws ServiceException; + + Wallet getWalletById(String walletId) throws ServiceException; + + void addAmountToWallet(String walletId, Float amount) throws ServiceException; + + void debitFromWallet(String walletId, Float amount) throws ServiceException; +} diff --git a/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java new file mode 100644 index 0000000..7822985 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java @@ -0,0 +1,59 @@ +package com.educare.unitylend.service.impl; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.CommunityRepository; +import com.educare.unitylend.model.Community; +import com.educare.unitylend.service.CommunityService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@AllArgsConstructor +@Service +public class CommunityServiceImpl implements CommunityService { + private CommunityRepository communityRepository; + + public List getCommunities() throws ServiceException { + try { + List communityList = communityRepository.getAllCommunities(); + // log.info("userList ",userList); + return communityList; + } catch (Exception e) { + log.error("Error encountered during user fetching operation"); + throw new ServiceException("Error encountered during user fetch operation", e); + } + } + + @Override + public String getCommunityName(String communityTag) throws ServiceException { + try { + String communityName= communityRepository.getCommunity(communityTag); + // log.info("userList ",userList); + return communityName; + } catch (Exception e) { + log.error("Error encountered during user fetching operation"); + throw new ServiceException("Error encountered during user fetch operation", e); + } + } + + public void createCommunity(Community newCommunity) throws ServiceException { + + try { + if (!communityRepository.existsByCommontag(newCommunity.getCommontag())) { + + communityRepository.createCommunity(newCommunity); + } + + + } catch (Exception e) { + log.error("Error encountered during user creation operation"); + throw new ServiceException("Error encountered during user creation operation", e); + } + } + + + +} 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 288147c..bce7a9f 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -1,13 +1,19 @@ package com.educare.unitylend.service.impl; import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.controller.UserCommunityController; +import com.educare.unitylend.dao.CommunityRepository; +import com.educare.unitylend.dao.UserCommunityRepository; import com.educare.unitylend.dao.UserRepository; +import com.educare.unitylend.dao.WalletRepository; import com.educare.unitylend.model.User; import com.educare.unitylend.service.UserService; +import com.educare.unitylend.service.WalletService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Slf4j @@ -16,15 +22,20 @@ public class UserServiceImpl implements UserService { private UserRepository userRepository; - + private WalletRepository walletRepository; + private WalletService walletService; + 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 fetch operation"); + log.error("Error encountered during user fetching operation"); throw new ServiceException("Error encountered during user fetch operation", e); } } @@ -40,4 +51,82 @@ public User getUserByUserId(String userId) throws ServiceException { 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)); + } + + walletService.generateWallet(newUser.getUserid()); + + } 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 { + userRepository.updateUser(user); + } catch (Exception e) { + log.error("Error encountered during user fetching operation"); + throw new ServiceException("Error encountered during user fetch operation", e); + } + } + } diff --git a/src/main/java/com/educare/unitylend/service/impl/WalletServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/WalletServiceImpl.java new file mode 100644 index 0000000..75b42db --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/impl/WalletServiceImpl.java @@ -0,0 +1,95 @@ +package com.educare.unitylend.service.impl; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.WalletRepository; +import com.educare.unitylend.model.User; +import com.educare.unitylend.model.Wallet; +import com.educare.unitylend.service.WalletService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +import java.util.ArrayList; +import java.util.List; + + +@Slf4j +@AllArgsConstructor +@Service +public class WalletServiceImpl implements WalletService{ + WalletRepository walletRepository; + + + @Override + public List getWallets() throws ServiceException { + try { + List walletList = walletRepository.getAllWallets(); + log.info("walletList ", walletList); + return walletList; + } catch (Exception e) { + log.error("Error encountered during wallet fetching operation"); + throw new ServiceException("Error encountered during wallet fetch operation", e); + } + } + + + @Override + public Wallet getWalletInfo(String userId) throws ServiceException { + Wallet wallet = walletRepository.getWalletInfo(userId); + + + User user = walletRepository.getUserIdWithWallet(wallet); + wallet.setUser(user); + return wallet; + } + + + @Override + public void generateWallet(String userId) throws ServiceException { + walletRepository.generateWalletInTable(userId); + Wallet wallet = walletRepository.getWalletInfo(userId); + User user = walletRepository.getUserIdWithWallet(wallet); + wallet.setUser(user); + } + + + @Override + public Wallet getWalletById(String walletId) { + Wallet wallet = walletRepository.getWalletById(walletId); + User user = walletRepository.getUserIdWithWallet(wallet); + wallet.setUser(user); + return wallet; + } + + + @Override + @Transactional + public void addAmountToWallet(String walletId, Float amount) { + Wallet wallet = walletRepository.getWalletById(walletId); + if (wallet != null) { + Float currentBalance = wallet.getBalance(); + Float newBalance = currentBalance + amount; + wallet.setBalance(newBalance); + walletRepository.updateBalance(walletId, newBalance); + } else { + throw new RuntimeException("Wallet not found with id: " + walletId); + } + } + + + @Override + @Transactional + public void debitFromWallet(String walletId, Float amount) { + Wallet wallet = walletRepository.getWalletById(walletId); + if (wallet != null) { + Float currentBalance = wallet.getBalance(); + Float newBalance = currentBalance - amount; + wallet.setBalance(newBalance); + walletRepository.updateBalance(walletId, newBalance); + } else { + throw new RuntimeException("Wallet not found with id: " + walletId); + } + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index af09fad..b25bad3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,6 @@ - server.port=8085 - -spring.datasource.url=jdbc:postgresql://localhost:5432/unity-lend -spring.datasource.username=user -spring.datasource.password=password +spring.datasource.url=jdbc:postgresql://localhost:5432/unitylend +spring.datasource.username=postgres +spring.datasource.password=surabhi spring.datasource.driver-class-name=org.postgresql.Driver + diff --git a/src/main/resources/scratch.sql b/src/main/resources/scratch.sql new file mode 100644 index 0000000..ea13d69 --- /dev/null +++ b/src/main/resources/scratch.sql @@ -0,0 +1,1355 @@ + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- Create "User" table + +CREATE TABLE "User" ( + UserId VARCHAR(36), + Password VARCHAR(255) NOT NULL, + Name VARCHAR(255) NOT NULL, + Email VARCHAR(255) NOT NULL UNIQUE, + DOB DATE, + Income INTEGER NOT NULL, + OfficeName VARCHAR(255), + CollegeUniversity VARCHAR(255), + Locality VARCHAR(255), + PRIMARY KEY (UserId) -- Adding primary key constraint +); + +CREATE OR REPLACE FUNCTION check_age() +RETURNS TRIGGER AS $$ +BEGIN + IF NEW.DOB > CURRENT_DATE - INTERVAL '18 years' THEN + RAISE EXCEPTION 'Age must be at least 18 years.'; +END IF; +RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER check_age_trigger + BEFORE INSERT ON "User" + FOR EACH ROW + EXECUTE FUNCTION check_age(); + + +-- Create Community table + +CREATE TABLE Community ( + CommunityId CHAR(36) PRIMARY KEY, + CommunityName VARCHAR(255) NOT NULL, + CommonTag VARCHAR(255) NOT NULL +); + +-- Junction table to represent the many-to-many relationship between "User"s and communities + +CREATE TABLE UserCommunity ( + UserId CHAR(36), + CommunityId CHAR(36), + PRIMARY KEY (UserId, CommunityId), + FOREIGN KEY (UserId) REFERENCES "User"(UserId), + FOREIGN KEY (CommunityId) REFERENCES Community(CommunityId) +); + +-- Create Borrow_Request table +CREATE TABLE Borrow_Request ( + RequestID CHAR(36) PRIMARY KEY, + BorrowerID CHAR(36), + CommunityID CHAR(36), + ReturnPeriod INT NOT NULL, + Status VARCHAR(20) DEFAULT 'Pending' , + Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , + CollectedAmount DECIMAL(10, 2) DEFAULT 0.00 , + TargetAmount DECIMAL(10, 2) NOT NULL, + FOREIGN KEY (BorrowerID) REFERENCES "User"(UserId), + FOREIGN KEY (CommunityID) REFERENCES Community(CommunityId) +); + +-- Create Lending_Transaction table +CREATE TABLE Lending_Transaction ( + LendTransactionId CHAR(36) PRIMARY KEY, + LenderId CHAR(36), + BorrowerId CHAR(36), + RequestId CHAR(36), + Amount DECIMAL(10, 2) NOT NULL, + Timestamp TIMESTAMP NOT NULL, + FOREIGN KEY (LenderId) REFERENCES "User"(UserId), + FOREIGN KEY (BorrowerId) REFERENCES "User"(UserId), + FOREIGN KEY (RequestId) REFERENCES Borrow_Request(RequestID) +); + +-- Create Repayment_Transaction table +CREATE TABLE Repayment_Transaction ( + RepayTransactionId CHAR(36) PRIMARY KEY, + PayerId CHAR(36), + PayeeId CHAR(36), + RequestId CHAR(36), + Amount DECIMAL(10, 2) NOT NULL, + Timestamp TIMESTAMP NOT NULL, + FOREIGN KEY (PayerId) REFERENCES "User"(UserId), + FOREIGN KEY (PayeeId) REFERENCES "User"(UserId), + FOREIGN KEY (RequestId) REFERENCES Borrow_Request(RequestID) +); + +-- Create Wallet table +CREATE TABLE Wallet ( + WalletId CHAR(36) PRIMARY KEY, + UserId CHAR(36), + Balance DECIMAL(10, 2) NOT NULL, + FOREIGN KEY (UserId) REFERENCES "User"(UserId) +); + +Queries to populate the dummy data into tables + +-- Inserting dummy data into the "User" table + +INSERT INTO "User" (UserId, Password, Name, Email, DOB, Income) +VALUES +(uuid_generate_v4(), 'pass123', 'Aarav Patel', 'aarav@example.com', '1990-01-01', 50000.00), +(uuid_generate_v4(), 'pass456', 'Aaradhya Sharma', 'aaradhya@example.com', '1985-05-15', 60000.00), +(uuid_generate_v4(), 'pass789', 'Aarav Singh', 'aaravsingh@example.com', '1993-08-20', 45000.00), +(uuid_generate_v4(), 'passabc', 'Abhinav Gupta', 'abhinavgupta@example.com', '1980-03-10', 70000.00), +(uuid_generate_v4(), 'pass123', 'Aditi Mishra', 'aditi@example.com', '1988-09-25', 55000.00), +(uuid_generate_v4(), 'pass456', 'Advait Tiwari', 'advait@example.com', '1995-06-12', 62000.00), +(uuid_generate_v4(), 'pass789', 'Akshay Joshi', 'akshayjoshi@example.com', '1991-11-08', 48000.00), +(uuid_generate_v4(), 'passabc', 'Ananya Singh', 'ananya@example.com', '1975-04-17', 72000.00), +(uuid_generate_v4(), 'pass123', 'Arya Dubey', 'arya@example.com', '1983-02-20', 51000.00), +(uuid_generate_v4(), 'pass456', 'Avani Patel', 'avani@example.com', '1987-07-30', 63000.00), +(uuid_generate_v4(), 'pass789', 'Ayaan Kumar', 'ayaan@example.com', '1990-05-05', 46000.00), +(uuid_generate_v4(), 'passabc', 'Bhavna Shah', 'bhavna@example.com', '1982-10-12', 71000.00), +(uuid_generate_v4(), 'pass123', 'Charvi Sharma', 'charvi@example.com', '1989-12-04', 52000.00), +(uuid_generate_v4(), 'pass456', 'Darsh Jain', 'darsh@example.com', '1984-08-18', 64000.00), +(uuid_generate_v4(), 'pass789', 'Dev Singh', 'devsingh@example.com', '1986-03-22', 47000.00), +(uuid_generate_v4(), 'passabc', 'Dhruv Gupta', 'dhruv@example.com', '1992-01-15', 69000.00), +(uuid_generate_v4(), 'pass123', 'Eshaan Gupta', 'eshaan@example.com', '1978-06-28', 53000.00), +(uuid_generate_v4(), 'pass456', 'Garima Mishra', 'garima@example.com', '1994-04-03', 65000.00); + + + +-- Inserting dummy data into the Community table for 5 rows + +INSERT INTO Community (CommunityId, CommunityName, CommonTag) +VALUES + (uuid_generate_v4(), 'Community A','D.E.Shaw'), + (uuid_generate_v4(), 'Community B','Delhi Public School'), + (uuid_generate_v4(), 'Community C','Sri Chaitanya School'), + (uuid_generate_v4(), 'Community D','IIM Ahmedabad'), + (uuid_generate_v4(), 'Community E','ISB Hyderabad'); + + + + +-- Inserting dummy data into the UserCommunity table + +INSERT INTO UserCommunity (UserId, CommunityId) +VALUES + ((SELECT UserId FROM "User" WHERE Name = 'Aarav Patel'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Aaradhya Sharma'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Aarav Singh'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Abhinav Gupta'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Aditi Mishra'), (SELECT CommunityId from Community where CommunityName='Community E')), + ((SELECT UserId FROM "User" WHERE Name = 'Advait Tiwari'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Akshay Joshi'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Ananya Singh'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Arya Dubey'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Avani Patel'), (SELECT CommunityId from Community where CommunityName='Community E')), + ((SELECT UserId FROM "User" WHERE Name = 'Ayaan Kumar'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Bhavna Shah'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Charvi Sharma'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Darsh Jain'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Dev Singh'), (SELECT CommunityId from Community where CommunityName='Community E')), + ((SELECT UserId FROM "User" WHERE Name = 'Dhruv Gupta'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Eshaan Gupta'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Garima Mishra'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Aarav Patel'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Aaradhya Sharma'), (SELECT CommunityId from Community where CommunityName='Community E')), + ((SELECT UserId FROM "User" WHERE Name = 'Aarav Singh'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Abhinav Gupta'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Aditi Mishra'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Advait Tiwari'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Akshay Joshi'), (SELECT CommunityId from Community where CommunityName='Community E')), + ((SELECT UserId FROM "User" WHERE Name = 'Ananya Singh'), (SELECT CommunityId from Community where CommunityName='Community A')), + ((SELECT UserId FROM "User" WHERE Name = 'Arya Dubey'), (SELECT CommunityId from Community where CommunityName='Community B')), + ((SELECT UserId FROM "User" WHERE Name = 'Avani Patel'), (SELECT CommunityId from Community where CommunityName='Community C')), + ((SELECT UserId FROM "User" WHERE Name = 'Ayaan Kumar'), (SELECT CommunityId from Community where CommunityName='Community D')), + ((SELECT UserId FROM "User" WHERE Name = 'Bhavna Shah'), (SELECT CommunityId from Community where CommunityName='Community E')); + +-- Inserting dummy data into the Borrow_Request table + +INSERT INTO Borrow_Request (RequestID, BorrowerID, CommunityID, ReturnPeriod, Status, Timestamp, CollectedAmount, TargetAmount) +VALUES + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Aarav Patel'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community A'), 60, 'Pending', NOW(), 0.00, 2500.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Aaradhya Sharma'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community B'), 35, 'Fulfilled', NOW(), 2200.00, 2200.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Ananya Singh'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community C'), 45, 'Pending', NOW(), 0.00, 2700.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Dev Singh'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community E'), 55, 'Fulfilled', NOW(), 2800.00, 2800.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Aarav Singh'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community C'), 40, 'Pending', NOW(), 0.00, 2000.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Garima Mishra'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community C'), 25, 'Pending', NOW(), 1500.00, 2300.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Ayaan Kumar'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community D'), 50, 'Fulfilled', NOW(), 2500.00, 2500.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Avani Patel'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community C'), 30, 'Pending', NOW(), 0.00, 2200.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Charvi Sharma'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community C'), 40, 'Pending', NOW(), 0.00, 2700.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Darsh Jain'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community D'), 55, 'Fulfilled', NOW(), 2800.00, 2800.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Dhruv Gupta'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community A'), 35, 'Pending', NOW(), 0.00, 2000.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Ayaan Kumar'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community A'), 45, 'Fulfilled', NOW(), 2700.00, 2700.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Avani Patel'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community E'), 30, 'Pending', NOW(), 0.00, 2200.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Arya Dubey'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community D'), 50, 'Pending', NOW(), 0.00, 2800.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Ananya Singh'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community A'), 40, 'Fulfilled', NOW(), 3000.00, 3000.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Akshay Joshi'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community B'), 35, 'Pending', NOW(), 0.00, 2000.00), + (uuid_generate_v4(), (SELECT UserId FROM "User" WHERE Name = 'Advait Tiwari'), (SELECT CommunityId FROM Community WHERE CommunityName = 'Community A'), 55, 'Pending', NOW(), 0.00, 2500.00); + + +-- Inserting dummy data into the Lending_Transaction table + +INSERT INTO Lending_Transaction (LenderId, BorrowerId, LendTransactionId, RequestId, +Amount, Timestamp) +VALUES +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Eshaan Gupta' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +), uuid_generate_v4(), (SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +)), 1000.00, NOW()), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Abhinav Gupta' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +), uuid_generate_v4(), (SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +)), 500.00, NOW()), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Arya Dubey' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +), uuid_generate_v4(), (SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' +)), 600.00, NOW()), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Singh' AND c.CommunityName = 'Community C' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ) + ), + 300.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Charvi Sharma' AND c.CommunityName = 'Community C' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ) + ), + 1100.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Charvi Sharma' AND c.CommunityName = 'Community C' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Garima Mishra' AND c.CommunityName = 'Community C' + ) + ), + 900.00, + NOW() +), + + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aditi Mishra' AND c.CommunityName = 'Community E' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ) + ), + 1100.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Bhavna Shah' AND c.CommunityName = 'Community E' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ) + ), + 500.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Akshay Joshi' AND c.CommunityName = 'Community E' + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ) + ), + 1200.00, + NOW() +), + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Akshay Joshi' AND c.CommunityName = 'Community E' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + LIMIT 1 + ) + LIMIT 1 + ), + 1200.00, + NOW() +), + + + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Patel' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 500.00, + NOW() +), + + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Arya Dubey' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 1000.00, + NOW() +), +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Advait Tiwari' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 1000.00, + NOW() +), + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Patel' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 600.00, + NOW() +), + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Advait Tiwari' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 300.00, + NOW() +), + + + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 700.00, + NOW() +), + +( + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dhruv Gupta' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT MAX(RequestId) + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT MAX(u.UserId) + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1100.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1500.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1000.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dhruv Gupta' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 500.00, + NOW() +); + + +-- Inserting dummy data into the Repayment_Transaction table + +INSERT INTO Repayment_Transaction (PayerId, PayeeId, RepayTransactionId, RequestId, + Amount, Timestamp) +VALUES + ((SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Eshaan Gupta' AND c.CommunityName = 'Community B' + ) , uuid_generate_v4(),(SELECT RequestId + FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + )), 1047.00 ,NOW()), + + + + ((SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Abhinav Gupta' AND c.CommunityName = 'Community B' + ) , uuid_generate_v4(),(SELECT RequestId + FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + )), 523.00 ,NOW()), + + ((SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Arya Dubey' AND c.CommunityName = 'Community B' + ) , uuid_generate_v4(),(SELECT RequestId + FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aaradhya Sharma' AND c.CommunityName = 'Community B' + )), 628.00 ,NOW()), + + ( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Patel' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 523.00, + NOW() + ), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Arya Dubey' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 1068.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Advait Tiwari' AND c.CommunityName = 'Community D' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community D' + LIMIT 1 + ) + LIMIT 1 + ), + 1068.00, + NOW() +), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Bhavna Shah' AND c.CommunityName = 'Community E' + ) , uuid_generate_v4(),(SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' +)), 537.00 ,NOW()), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Aditi Mishra' AND c.CommunityName = 'Community E' + ) , uuid_generate_v4(),(SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' +)), 1182.00 ,NOW()), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Akshay Joshi' AND c.CommunityName = 'Community E' + ) , uuid_generate_v4(),(SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Dev Singh' AND c.CommunityName = 'Community E' +)), 1290.00 ,NOW()), +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Darsh Jain' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Abhinav Gupta' AND c.CommunityName = 'Community B' + ) , uuid_generate_v4(),(SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Darsh Jain' AND c.CommunityName = 'Community B' +)), 1505.00 ,NOW()), + +((SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Darsh Jain' AND c.CommunityName = 'Community B' + ), (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Arya Dubey' AND c.CommunityName = 'Community B' + ) , uuid_generate_v4(),(SELECT RequestId +FROM Borrow_Request WHERE BorrowerId = (SELECT u.UserId +FROM "User" u +JOIN UserCommunity uc ON u.UserId = uc.UserId +JOIN Community c ON uc.CommunityId = c.CommunityId +WHERE u.Name = 'Darsh Jain' AND c.CommunityName = 'Community B' +)), 1505.00 ,NOW()), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Patel' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 636.00, + NOW() +), + + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Advait Tiwari' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 318.00, + NOW() +), + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dhruv Gupta' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 743.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1167.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Aarav Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1582.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ayaan Kumar' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1054.00, + NOW() +), + + +( + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Dhruv Gupta' AND c.CommunityName = 'Community A' + LIMIT 1 + ), + uuid_generate_v4(), + ( + SELECT RequestId + FROM Borrow_Request + WHERE BorrowerId = ( + SELECT u.UserId + FROM "User" u + JOIN UserCommunity uc ON u.UserId = uc.UserId + JOIN Community c ON uc.CommunityId = c.CommunityId + WHERE u.Name = 'Ananya Singh' AND c.CommunityName = 'Community A' + LIMIT 1 + ) + LIMIT 1 + ), + 1582.00, + NOW() +); + + + +-- Generate and insert dummy data into the Wallet table for each "User" +INSERT INTO Wallet (WalletId, UserId, Balance) +SELECT + uuid_generate_v4() AS WalletId, + u.UserId, + ROUND(CAST(RANDOM() * 100000 AS numeric), 2) AS Balance +FROM + "User" u; +