diff --git a/.gitignore b/.gitignore index b8d7e04..f80b0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ logs/ .nfs* pom.xml +application.properties src/main/resources/application.properties diff --git a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java index 1cdf057..ee1018a 100644 --- a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java +++ b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java @@ -56,14 +56,14 @@ ResponseEntity> getBorrowRequestForUserId(@PathVariable Stri * @throws ControllerException If an error occurs during the borrow request retrieval process. */ @GetMapping("/get-borrow-request-by-community-id/{communityId}") - ResponseEntity> getBorrowRequestForCommunity(@PathVariable String communityId) throws ControllerException { + ResponseEntity> getBorrowRequestForCommunity() throws ControllerException { return null; } /** * API endpoint for retrieving borrow requests in a community within an amount range. - * + *@PathVariable String communityId * @param minAmount The minimum amount of the borrow requests. * @param maxAmount The maximum amount of the borrow requests. * @param lessThan Flag indicating if the amount should be less than maxAmount. @@ -71,44 +71,47 @@ ResponseEntity> getBorrowRequestForCommunity(@PathVariable S * @return ResponseEntity> The list of borrow requests in the community within the specified amount range. * @throws ControllerException If an error occurs during the borrow request retrieval process. */ - @GetMapping("/get-borrow-request-in-community-by-amount") + @PostMapping("/get-borrow-request-in-community-by-amount/{communityId}") ResponseEntity> getBorrowRequestsInCommunityInAmountRange( @RequestParam(value = "minAmount", required = false) BigDecimal minAmount, - @RequestParam(value = "maxAmount", required = false) BigDecimal maxAmount, + @RequestParam(value = "maxAmount", required = true) BigDecimal maxAmount, @RequestParam(value = "lessThan", required = false, defaultValue = "false") boolean lessThan, - @RequestParam(value = "greaterThan", required = false, defaultValue = "true") boolean greaterThan + @RequestParam(value = "greaterThan", required = false, defaultValue = "true") boolean greaterThan, + @PathVariable String communityId ) throws ControllerException { try{ + log.info("minAmount: {}", minAmount); + log.info("maxAmount: {}", maxAmount); + log.info("lessThan: {}", lessThan); + log.info("greaterThan: {}", greaterThan); + log.info("communityId: {}", communityId); List borrowRequests = new ArrayList<>(); - if (minAmount != null && maxAmount != null) { - if (minAmount.compareTo(maxAmount) >= 0) { + if (minAmount.compareTo(maxAmount) > 0) { log.error("minAmount is greater than maxAmount which is not permissible"); return ResponseEntity.badRequest().body(borrowRequests); } } - else if(minAmount==null && maxAmount==null){ log.error("Both minAmount and maxAmount are empty"); return ResponseEntity.badRequest().body(borrowRequests); } - if(lessThan && greaterThan){ + log.error("Inaccurate Constrains"); return ResponseEntity.badRequest().body(borrowRequests); } else if(lessThan){ - borrowRequests=borrowRequestService.getBorrowRequestsInCommunityLessThanAmount(maxAmount); + borrowRequests=borrowRequestService.getBorrowRequestsInCommunityLessThanAmount(maxAmount, communityId); } else if(greaterThan){ - borrowRequests=borrowRequestService.getBorrowRequestsInCommunityGreaterThanAmount(minAmount); + borrowRequests=borrowRequestService.getBorrowRequestsInCommunityGreaterThanAmount(minAmount, communityId); } else{ - borrowRequests=borrowRequestService.getBorrowRequestsInCommunityInRange(minAmount,maxAmount); + borrowRequests=borrowRequestService.getBorrowRequestsInCommunityInRange(minAmount,maxAmount, communityId); } - +// log.info(borrowRequests); return ResponseEntity.ok(borrowRequests); } - catch(ServiceException e){ log.error("Error in filtering borrow requests based on amount"); throw new ControllerException("Error in filtering borrow requests based on amount",e); diff --git a/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java index 743055d..e5066a5 100644 --- a/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java +++ b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java @@ -1,10 +1,82 @@ package com.educare.unitylend.dao; +import com.educare.unitylend.model.BorrowRequest; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; +import java.math.BigDecimal; +import java.util.List; + @Mapper @Repository public interface BorrowRequestRepository { + @Select("SELECT " + + "borrow_request.borrow_request_id AS borrowRequestId," + + "borrow_request.return_period_days AS returnPeriodDays," + + "borrow_request.monthly_interest_rate AS monthlyInterestRate," + + "borrow_request.borrow_status AS borrowStatus," + + "borrow_request.requested_amount AS requestedAmount," + + "borrow_request.collected_amount AS collectedAmount," + + "borrow_request.is_defaulted AS isDefaulted," + + "borrow_request.default_fine AS defaultFine," + + "borrow_request.default_count AS defaultCount," + + "borrow_request.created_at AS createdAt," + + "borrow_request.last_modified_at AS lastModifiedAt " + + "FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " + + "WHERE borrow_request.requested_amount <= #{maxAmount}" + + " AND " + + "borrow_request_community_map.community_id = #{communityId}" + ) + List findByRequestedAmountLessThanAndCommunityIdsContaining( + @Param("maxAmount") BigDecimal maxAmount, + @Param("communityId") String communityId + ); + + @Select("SELECT " + + "borrow_request.borrow_request_id AS borrowRequestId," + + "borrow_request.return_period_days AS returnPeriodDays," + + "borrow_request.monthly_interest_rate AS monthlyInterestRate," + + "borrow_request.borrow_status AS borrowStatus," + + "borrow_request.requested_amount AS requestedAmount," + + "borrow_request.collected_amount AS collectedAmount," + + "borrow_request.is_defaulted AS isDefaulted," + + "borrow_request.default_fine AS defaultFine," + + "borrow_request.default_count AS defaultCount," + + "borrow_request.created_at AS createdAt," + + "borrow_request.last_modified_at AS lastModifiedAt " + + "FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " + + "WHERE borrow_request.requested_amount >= #{minAmount}" + + " AND " + + "borrow_request_community_map.community_id = #{communityId}" + ) + List findByRequestedAmountGreaterThanEqualAndCommunityIdsContaining( + @Param("minAmount") BigDecimal minAmount, + @Param("communityId") String communityId); + + @Select("SELECT " + + "borrow_request.borrow_request_id AS borrowRequestId," + + "borrow_request.return_period_days AS returnPeriodDays," + + "borrow_request.monthly_interest_rate AS monthlyInterestRate," + + "borrow_request.borrow_status AS borrowStatus," + + "borrow_request.requested_amount AS requestedAmount," + + "borrow_request.collected_amount AS collectedAmount," + + "borrow_request.is_defaulted AS isDefaulted," + + "borrow_request.default_fine AS defaultFine," + + "borrow_request.default_count AS defaultCount," + + "borrow_request.created_at AS createdAt," + + "borrow_request.last_modified_at AS lastModifiedAt " + + "FROM borrow_request INNER JOIN borrow_request_community_map using(borrow_request_id) " + + "WHERE borrow_request.requested_amount <= #{maxAmount}" + + " AND " + "borrow_request.requested_amount >= #{minAmount}" + + " AND " + + "borrow_request_community_map.community_id = #{communityId}" + ) + List findByRequestedAmountBetweenAndCommunityIdsContaining( + @Param("minAmount") BigDecimal minAmount, + @Param("maxAmount") BigDecimal maxAmount, + @Param("communityId") String communityId); + } \ No newline at end of file diff --git a/src/main/java/com/educare/unitylend/model/BorrowRequest.java b/src/main/java/com/educare/unitylend/model/BorrowRequest.java index 53e587d..d0cee6a 100644 --- a/src/main/java/com/educare/unitylend/model/BorrowRequest.java +++ b/src/main/java/com/educare/unitylend/model/BorrowRequest.java @@ -16,7 +16,7 @@ @AllArgsConstructor public class BorrowRequest { private String borrowRequestId; - private User borrower; + private String borrower_id; private Integer returnPeriodDays; private BigDecimal monthlyInterestRate; private Status borrowStatus; @@ -28,4 +28,6 @@ public class BorrowRequest { private LocalDateTime createdAt; private LocalDateTime lastModifiedAt; private List communityIds; + + } diff --git a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java index a611f4e..c32dab6 100644 --- a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java +++ b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java @@ -13,8 +13,8 @@ public interface BorrowRequestService { List getBorrowRequestForCommunity(String communityId) throws ServiceException; Boolean updateEMIDefaults() throws ServiceException; Boolean updateBorrowRequestStatus(Status status) throws ServiceException; - List getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount) throws ServiceException; - List getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount) throws ServiceException; - List getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount) throws ServiceException; + List getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount, String communityId) throws ServiceException; + List getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount, String communityId) throws ServiceException; + List getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount, String communityId) throws ServiceException; List getAllBorrowRequests() throws ServiceException; } \ No newline at end of file diff --git a/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java index 48acae2..10173e3 100644 --- a/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java @@ -1,6 +1,7 @@ package com.educare.unitylend.service.impl; import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.BorrowRequestRepository; import com.educare.unitylend.model.BorrowRequest; import com.educare.unitylend.model.Status; import com.educare.unitylend.service.BorrowRequestService; @@ -15,7 +16,7 @@ @AllArgsConstructor @Service public class BorrowRequestServiceImpl implements BorrowRequestService { - + BorrowRequestRepository borrowRequestRepository; @Override public List getAllBorrowRequests() throws ServiceException { return null; @@ -47,17 +48,32 @@ public Boolean updateBorrowRequestStatus(Status status) throws ServiceException } @Override - public List getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount) throws ServiceException { - return null; + public List getBorrowRequestsInCommunityLessThanAmount(BigDecimal maxAmount, String communityId) throws ServiceException { + try { + + + return borrowRequestRepository.findByRequestedAmountLessThanAndCommunityIdsContaining(maxAmount, communityId); + } catch (Exception e) { + throw new ServiceException("Error retrieving borrow requests with amount less than " + maxAmount, e); + } } @Override - public List getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount) throws ServiceException { - return null; + public List getBorrowRequestsInCommunityGreaterThanAmount(BigDecimal minAmount, String communityId) throws ServiceException { + try { + return borrowRequestRepository.findByRequestedAmountGreaterThanEqualAndCommunityIdsContaining(minAmount, communityId); + } catch (Exception e) { + throw new ServiceException("Error retrieving borrow requests with amount greater than or equal to " + minAmount, e); + } } @Override - public List getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount) throws ServiceException { - return null; + public List getBorrowRequestsInCommunityInRange(BigDecimal minAmount, BigDecimal maxAmount, String communityId) throws ServiceException { + try { + return borrowRequestRepository.findByRequestedAmountBetweenAndCommunityIdsContaining(minAmount, maxAmount, communityId); + } catch (Exception e) { + throw new ServiceException("Error retrieving borrow requests with amount between " + minAmount + " and " + maxAmount, e); + } } + } diff --git a/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java index dce7f45..167b9db 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java @@ -1,7 +1,7 @@ package com.educare.unitylend.service.impl; import com.educare.unitylend.Exception.ServiceException; -import com.educare.unitylend.dao.UserCommunityRepository; +import com.educare.unitylend.dao.UserCommunityMapRepository; import com.educare.unitylend.model.User; import com.educare.unitylend.service.UserCommunityService; import com.educare.unitylend.service.UserService; @@ -15,12 +15,12 @@ @AllArgsConstructor @Service public class UserCommunityServiceImpl implements UserCommunityService { - private UserCommunityRepository userCommunityRepository; + private UserCommunityMapRepository userCommunityRepository; public List getCommunitiesByUserId(String userId) throws ServiceException{ - try { - List communityNames = userCommunityRepository.findCommunityNamesByUserId(userId); + try { return null; + // List communityNames = userCommunityRepository.findCommunityNamesByUserId(userId); // log.info("communityNames: ", communityNames); - return communityNames; + //return communityNames; } catch (Exception e) { log.error("Error encountered during community fetching operation for user with ID: {}", userId, e); throw new ServiceException("Error encountered during community fetch operation", e); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d597aca..466aa0e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,8 @@ server.port=8085 -spring.datasource.url=jdbc:postgresql://localhost:5432/unity-lend +spring.datasource.url=jdbc:postgresql://localhost:5432/final spring.datasource.username=postgres -spring.datasource.password=postgres +spring.datasource.password=UnityLend spring.datasource.driver-class-name=org.postgresql.Driver diff --git a/src/main/resources/scratch.sql b/src/main/resources/scratch.sql index ea5e9f2..735afaf 100644 --- a/src/main/resources/scratch.sql +++ b/src/main/resources/scratch.sql @@ -1,1365 +1,609 @@ +-- CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +-- +-- +-- +-- -- Create user_detail table +-- +-- +-- +-- CREATE TABLE user_detail ( +-- +-- user_id CHAR(36), +-- +-- password VARCHAR(255) NOT NULL, +-- +-- name VARCHAR(255) NOT NULL, +-- +-- email VARCHAR(255) NOT NULL UNIQUE, +-- +-- contact_no VARCHAR(255) UNIQUE, +-- +-- dob DATE, +-- +-- income INTEGER NOT NULL, +-- +-- community_details JSON, +-- +-- PRIMARY KEY (user_id) -- 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_detail +-- +-- FOR EACH ROW +-- +-- EXECUTE PROCEDURE check_age(); +-- +-- +-- +-- +-- +-- +-- +-- -- Create wallet table +-- +-- +-- +-- CREATE TABLE wallet( +-- +-- wallet_id CHAR(36) PRIMARY KEY, +-- +-- user_id CHAR(36) NOT NULL, +-- +-- balance DECIMAL(10,2) NOT NULL, +-- +-- FOREIGN KEY (user_id) REFERENCES user_detail (user_id) +-- +-- ); +-- +-- +-- +-- +-- +-- -- Create status table +-- +-- CREATE TABLE status( +-- +-- status_code INTEGER PRIMARY KEY, +-- +-- status_name VARCHAR(20) +-- +-- ); +-- +-- +-- +-- -- Create community table +-- +-- +-- +-- CREATE TABLE community( +-- +-- community_id CHAR(36) PRIMARY KEY, +-- +-- community_name VARCHAR(255) NOT NULL, +-- +-- community_tag VARCHAR(255) NOT NULL, +-- +-- community_detail VARCHAR(255) +-- +-- ); +-- +-- +-- +-- +-- +-- +-- +-- -- Create user_community_map table +-- +-- +-- +-- CREATE TABLE user_community_map( +-- +-- user_id CHAR(36), +-- +-- community_id CHAR(36), +-- +-- PRIMARY KEY (user_id, community_id), +-- +-- FOREIGN KEY (user_id) REFERENCES user_detail (user_id), +-- +-- FOREIGN KEY (community_id) REFERENCES community(community_id) +-- +-- ); +-- +-- +-- +-- +-- +-- +-- +-- -- Create borrow_request table +-- +-- +-- +-- CREATE TABLE borrow_request( +-- +-- borrow_request_id CHAR(36) PRIMARY KEY, +-- +-- borrower_id CHAR(36) NOT NULL, +-- +-- return_period_days INTEGER NOT NULL, +-- +-- monthly_interest_rate DECIMAL(10,2) NOT NULL, +-- +-- borrow_status INTEGER, +-- +-- requested_amount DECIMAL(10,2) NOT NULL DEFAULT 0.00, +-- +-- collected_amount DECIMAL(10,2) NOT NULL DEFAULT 0.00, +-- +-- is_defaulted BOOLEAN DEFAULT false, +-- +-- default_fine DECIMAL(10,2) DEFAULT 0.00, +-- +-- default_count INTEGER DEFAULT 0, +-- +-- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- last_modified_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- FOREIGN KEY (borrower_id) REFERENCES user_detail(user_id), +-- +-- FOREIGN KEY (borrow_status ) REFERENCES status (status_code) +-- +-- ); +-- +-- +-- +-- -- Create borrow_request_community map +-- +-- +-- +-- CREATE TABLE borrow_request_community_map( +-- +-- borrow_request_id CHAR(36), +-- +-- community_id CHAR(36), +-- +-- PRIMARY KEY (borrow_request_id, community_id), +-- +-- FOREIGN KEY (borrow_request_id) REFERENCES borrow_request (borrow_request_id), +-- +-- FOREIGN KEY (community_id) REFERENCES community (community_id) +-- +-- ); +-- +-- +-- +-- +-- +-- +-- +-- -- Create transaction table +-- +-- +-- +-- CREATE TABLE transaction( +-- +-- transaction_id CHAR(36) PRIMARY KEY, +-- +-- receiver_id CHAR(36), +-- +-- sender_id CHAR(36), +-- +-- amount DECIMAL(10,2) NOT NULL DEFAULT 0.00, +-- +-- transaction_status INTEGER, +-- +-- transaction_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- last_updated_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- FOREIGN KEY (receiver_id) REFERENCES user_detail (user_id), +-- +-- FOREIGN KEY (sender_id) REFERENCES user_detail (user_id), +-- +-- FOREIGN KEY (transaction_status) REFERENCES status (status_code) +-- +-- ); +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- -- Create lend_transaction table +-- +-- +-- +-- CREATE TABLE lend_transaction( +-- +-- lend_transaction_id CHAR(36) PRIMARY KEY, +-- +-- transaction_id CHAR(36), +-- +-- borrow_request_id CHAR(36), +-- +-- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- last_updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- FOREIGN KEY (transaction_id) REFERENCES transaction (transaction_id), +-- +-- FOREIGN KEY (borrow_request_id) REFERENCES borrow_request (borrow_request_id) +-- +-- ); +-- +-- +-- +-- -- Create repayment_transaction table +-- +-- create TABLE repayment_transaction +-- +-- ( +-- +-- repayment_transaction_id char(36) PRIMARY KEY, +-- +-- transaction_id char(36) NOT NULL, +-- +-- borrow_request_id char(36) NOT NULL, +-- +-- created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- +-- FOREIGN KEY (transaction_id) REFERENCES transaction(transaction_id), +-- +-- FOREIGN KEY (borrow_request_id) REFERENCES borrow_request(borrow_request_id) +-- +-- ); +-- +-- +-- +-- --QUERIES TO ADD DATA TO THE DATABASE +-- +-- +-- +-- -- Inserting dummy data into the user_detail table +-- +-- +-- +-- -- INSERT INTO user_detail (user_id, password, name, email,contact_no, dob, income,community_details) +-- -- +-- -- VALUES +-- -- +-- -- (uuid_generate_v4(), 'pass456', 'Garima Mishra', 'garima@example.com', '8763282638', '1994-04-03', 65000, '{"school": "Sri Chaitanya School"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass456', 'Advait Tiwari', 'advait@example.com', '8763282639', '1995-06-12', 62000.00, '{"office": "D.E.Shaw", "university": "IIM Ahmedabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass123', 'Eshaan Gupta', 'eeshan@example.com', '9876543210', '1978-06-28', 53000, '{"school": "Delhi Public School"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass456', 'Aaradhya Sharma', 'aaradhya@example.com', '9876543211', '1985-05-15', 60000, '{"school": "Delhi Public School", "university": "ISB Hyderabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass123', 'Arya Dubey', 'arya@example.com', '8765432109', '1983-02-20', 51000.00, '{"university": "IIM Ahmedabad", "school": "Delhi Public school"}'), +-- -- +-- -- (uuid_generate_v4(), 'passabc', 'Ananya Singh', 'ananya@example.com', '9876543212', '1975-04-17', 72000, '{"school": "Sri Chaitanya School", "office": "D.E.Shaw"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass789', 'Dev Singh', 'devsingh@example.com', '8765432107', '1986-03-22', 47000, '{"university": "ISB Hyderabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass123', 'Aditi Mishra', 'aditi@example.com', '9876543213', '1988-09-25', 55000, '{"university": "ISB Hyderabad", "school": "Sri Chaitanya School"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass789', 'Akshay Joshi', 'akshayjoshi@example.com', '8765432108', '1991-11-08', 48000.00, '{"school": "Delhi Public School", "university": "ISB Hyderabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass123', 'Charvi Sharma', 'charvi@example.com', '9876543214', '1989-12-04', 52000, '{"school": "Sri Chaitanya School"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass789', 'Aarav Singh', 'aaravsingh@example.com', '8763282649', '1993-08-20', 45000, '{"school": "Sri Chaitanya School", "office": "D.E.Shaw"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass123', 'Aarav Patel', 'aarav@example.com', '9876543220', '1990-01-01', 50000, '{"office": "D.E.Shaw", "university": "IIM Ahmedabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'passabc', 'Dhruv Gupta', 'dhruv@example.com', '8765432129', '1992-01-15', 69000.00, '{"office": "D.E.Shaw"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass456', 'Avani Patel', 'avani@example.com', '9876543215', '1987-07-30', 63000, '{"university": "ISB Hyderabad", "school": "Sri Chaitanya School"}'), +-- -- +-- -- (uuid_generate_v4(), 'passabc', 'Bhavna Shah', 'bhavna@example.com', '8763282658', '1982-10-12', 71000, '{"school": "Delhi Public School", "university": "ISB Hyderabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass456', 'Darsh Jain', 'darsh@example.com', '9876543290', '1984-08-18', 64000, '{"university": "IIM Ahmedabad"}'), +-- -- +-- -- (uuid_generate_v4(), 'passabc', 'Abhinav Gupta', 'abhinavgupta@example.com', '8765432139', '1980-03-10', 70000.00, '{"university": "IIM Ahmedabad", "school": "Delhi Public School"}'), +-- -- +-- -- (uuid_generate_v4(), 'pass789', 'Ayaan Kumar', 'ayaan@example.com', '9876543230', '1990-05-05', 46000, '{"office": "D.E.Shaw", "university": "IIM Ahmedabad"}'); +-- -- +-- -- +-- -- +-- -- -- Generate and insert dummy data into the wallet table for each user +-- -- +-- -- INSERT INTO wallet (wallet_id, user_id , balance) +-- -- +-- -- SELECT +-- -- +-- -- uuid_generate_v4() AS wallet_id, +-- -- +-- -- u. user_id, ROUND(CAST(RANDOM() * 100000 AS numeric), 2) AS Balance FROM user_detail u; +-- -- +-- -- +-- -- +-- -- +-- +-- -- Inserting dummy data into the community table +-- +INSERT INTO community ( community_id, community_name,community_tag,community_detail) -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; - -alter table "TempUser" rename to "tempuser"; - -ALTER TABLE tempuser - ADD COLUMN isActive BOOLEAN DEFAULT true; - -ALTER TABLE community - ADD COLUMN communitytype VARCHAR(255); - - + (uuid_generate_v4(), 'D.E.Shaw','office','description'), + + (uuid_generate_v4(), 'IIM Ahmedabad','university','description'), + + (uuid_generate_v4(), 'Delhi Public School','school','description'), + + (uuid_generate_v4(), 'ISB Hyderabad','university','description'), + + (uuid_generate_v4(), 'Sri Chaitanya School','school','description'); +-- +-- INSERT INTO borrow_request (borrow_request_id, borrower_id, return_period_days,monthly_interest_rate, borrow_status,requested_amount,collected_amount,is_defaulted,default_fine,default_count,created_at) +-- VALUES +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email= 'aaravsingh@example.com'), 60, 5.00, 1, 2500.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='aaradhya@example.com'), 35, 5.00, 2, 2200.00, 2200.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='devsingh@example.com'), 55, 5.00, 2, 2800.00, 2800.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='aaravsingh@example.com'), 40, 5.00, 1, 2000.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='garima@example.com'), 25, 5.00, 1, 2300.00, 1500.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='ayaan@example.com'), 50, 5.00, 2, 2500.00, 2500.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='avani@example.com'), 30, 5.00, 1, 2200.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='charvi@example.com'), 40, 5.00, 1, 2700.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='darsh@example.com'), 55, 5.00, 2, 2800.00, 2800.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='dhruv@example.com'), 35, 5.00, 1, 2000.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='avani@example.com'), 30, 5.00, 1, 2200.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='arya@example.com'), 50, 5.00, 1, 2800.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='ananya@example.com'), 40, 5.00, 2, 3000.00, 3000.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='akshayjoshi@example.com'), 35, 5.00, 1, 2000.00, 0.00, false, 0, 0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='advait@example.com'), 55, 5.00, 1, 2500.00, 0.00, false, 0, 0, NOW()); +-- VALUES +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email= 'aaravsingh@example.com'), 60, 5.00,1, 2500.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='aaradhya@example.com'), 35, 5.00,2, 2200.00, 2200.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='devsingh@example.com'), 55, 5.00,2,2800.00, 2800.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='aaravsingh@example.com'), 40, 5.00,1, 2000.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='garima@example.com'), 25, 5.00,1, 2300.00, 1500.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='ayaan@example.com'), 50, 5.00,2, 2500.00, 2500.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='avani@example.com'), 30, 5.00,1, 2200.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='charvi@example.com'), 40, 5.00,1, 2700.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='darsh@example.com'), 55, 5.00,2, 2800.00, 2800.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='dhruv@example.com'), 35, 5.00,1, 2000.00,0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='avani@example.com'), 30, 5.00, 1, 2200.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='arya@example.com'), 50, 5.00,1, 2800.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='ananya@example.com'), 40, 5.00,2, 3000.00, 3000.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='akshayjoshi@example.com'), 35, 5.00,1, 2000.00, 0.00,0,0,0, NOW()), +-- (uuid_generate_v4(), (SELECT user_id FROM user_detail WHERE email='advait@example.com'), 55, 5.00,1, 2500.00, 0.00,0,0,0, NOW()); +-- +-- +-- +-- +-- +-- +-- +-- -- Inserting dummy data into the user_community table +-- +-- +-- +-- +-- +-- +-- +-- --inserting data into the status table +-- +-- +-- +-- INSERT INTO status (status_code, status_name) VALUES +-- +-- (1, 'Pending'), +-- +-- (2, 'Processing'), +-- +-- (3, 'Completed'); +-- +-- +-- +-- --inserting dummy data into the borrow request table +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- +-- -- Inserting dummy data into the transaction table +-- +-- INSERT INTO transaction (transaction_id ,receiver_id,sender_id, amount, transaction_status) +-- +-- VALUES +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aaradhya@example.com'), (SELECT user_id from user_detail where email= 'eshaan@example.com' ) ,1000,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aaradhya@example.com'), (SELECT user_id from user_detail where email= 'abhinavgupta@example.com' ),500 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aaradhya@example.com'), (SELECT user_id from user_detail where email= 'arya@example.com' ),600 ,3), +-- +-- +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='devsingh@example.com'), (SELECT user_id from user_detail where email= 'aditi@example.com' ),1100 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='devsingh@example.com'), (SELECT user_id from user_detail where email= 'bhavna@example.com' ),500 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='devsingh@example.com'), (SELECT user_id from user_detail where email= 'akshayjoshi@example.com' ) ,1200,3), +-- +-- +-- +-- +-- +-- +-- +-- --IIM Ahmedabad community +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'aarav@example.com' ) ,500,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'arya@example.com' ) ,1000,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'advait@example.com' ) ,1000,3), +-- +-- --D.E.Shaw community +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'aarav@example.com' ),600 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'advait@example.com' ) ,300,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'aaravsingh@example.com' ) ,700,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'dhruv@example.com' ) ,1100,3), +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ananya@example.com'), (SELECT user_id from user_detail where email= 'aaravsingh@example.com' ),1500 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ananya@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ),1000 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ananya@example.com'), (SELECT user_id from user_detail where email= 'dhruv@example.com' ),500 ,3), +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='eshaan@example.com'), (SELECT user_id from user_detail where email= 'aaradhya@example.com' ),1047 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='abhinavgupta@example.com'), (SELECT user_id from user_detail where email= 'aaradhya@example.com' ) ,523,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='arya@example.com' ), (SELECT user_id from user_detail where email='aaradhya@example.com' ),628 ,3), +-- +-- +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aditi@example.com'), (SELECT user_id from user_detail where email= 'devsingh@example.com' ),1182 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='bhavna@example.com' ), (SELECT user_id from user_detail where email= 'devsingh@example.com' ),537 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='akshayjoshi@example.com'), (SELECT user_id from user_detail where email= 'devsingh@example.com' ),1290 ,3), +-- +-- +-- +-- +-- +-- --IIM Ahmedabad community +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aarav@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ),523 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='arya@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ) ,1068,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='advait@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ),1068 ,3), +-- +-- --D.E.Shaw community +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aarav@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ) ,636,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='advait@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ),318 ,3), +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aaravsingh@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ) ,743,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='dhruv@example.com'), (SELECT user_id from user_detail where email= 'ayaan@example.com' ),1167 ,3), +-- +-- +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='aaravsingh@example.com'), (SELECT user_id from user_detail where email= 'ananya@example.com' ) ,1582,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='ayaan@example.com'), (SELECT user_id from user_detail where email= 'ananya@example.com' ),1054 ,3), +-- +-- (uuid_generate_v4(), (SELECT user_id from user_detail where email ='dhruv@example.com'), (SELECT user_id from user_detail where email= 'ananya@example.com' ) ,1582,3); +-- +-- +-- +-- +-- +-- +-- +-- -- Inserting dummy data into the LendTransaction table +-- +-- +-- +-- +-- +-- -- into lend_transaction(lend_transaction_id,transaction_id,borrow_request_id,created_at,last_updated_at) VALUES +-- +-- +-- +-- +-- +INSERT INTO user_community_map(user_id, community_id) VALUES + ((SELECT user_id FROM user_detail WHERE email = 'garima@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'advait@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')), + ((SELECT user_id FROM user_detail WHERE email = 'eeshan@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'aaradhya@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'aaradhya@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'arya@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')), + ((SELECT user_id FROM user_detail WHERE email = 'arya@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'ananya@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'ananya@example.com'), (SELECT community_id from community where community_name='D.E.Shaw')), + ((SELECT user_id FROM user_detail WHERE email = 'devsingh@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'aditi@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'aditi@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'akshayjoshi@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'akshayjoshi@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'charvi@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'aaravsingh@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'aaravsingh@example.com'), (SELECT community_id from community where community_name='D.E.Shaw')), + ((SELECT user_id FROM user_detail WHERE email = 'aarav@example.com'), (SELECT community_id from community where community_name='D.E.Shaw')), + ((SELECT user_id FROM user_detail WHERE email = 'aarav@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')), + ((SELECT user_id FROM user_detail WHERE email = 'dhruv@example.com'), (SELECT community_id from community where community_name='D.E.Shaw')), + ((SELECT user_id FROM user_detail WHERE email = 'avani@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'avani@example.com'), (SELECT community_id from community where community_name='Sri Chaitanya School')), + ((SELECT user_id FROM user_detail WHERE email = 'bhavna@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'bhavna@example.com'), (SELECT community_id from community where community_name='ISB Hyderabad')), + ((SELECT user_id FROM user_detail WHERE email = 'darsh@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')), + ((SELECT user_id FROM user_detail WHERE email = 'abhinavgupta@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')), + ((SELECT user_id FROM user_detail WHERE email = 'abhinavgupta@example.com'), (SELECT community_id from community where community_name='Delhi Public School')), + ((SELECT user_id FROM user_detail WHERE email = 'ayaan@example.com'), (SELECT community_id from community where community_name='D.E.Shaw')), + ((SELECT user_id FROM user_detail WHERE email = 'ayaan@example.com'), (SELECT community_id from community where community_name='IIM Ahmedabad')); + + + +-- Create borrow_request_community_map +INSERT INTO borrow_request_community_map (borrow_request_id, community_id) +SELECT br.borrow_request_id, uc.community_id +FROM borrow_request br + JOIN user_detail ud ON br.borrower_id = ud.user_id + JOIN user_community_map uc ON ud.user_id = uc.user_id;