From 25f4d09ffeba487cf878ee9de4109c472a5f9683 Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Sun, 25 Feb 2024 21:14:16 +0530 Subject: [PATCH 01/11] Move the DB schema under resources folder --- src/main/resources/scratch.sql | 1355 ++++++++++++++++++++++++++++++++ 1 file changed, 1355 insertions(+) create mode 100644 src/main/resources/scratch.sql 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; + From 08919bfbd4465a9c9999271bc474d6e053cc3a26 Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 03:31:59 +0530 Subject: [PATCH 02/11] Resolved Issue 9, 10 & 12 --- .../unitylend/UnitylendApplication.java | 2 +- .../controller/CommunityController.java | 58 +++++++++++++ .../unitylend/controller/UserController.java | 42 ++++++++-- .../educare/unitylend/dao/UserRepository.java | 29 ++++--- .../educare/unitylend/model/Community.java | 7 +- .../com/educare/unitylend/model/User.java | 83 +++++++++++++++++-- .../unitylend/service/CommunityService.java | 13 +++ .../unitylend/service/UserService.java | 2 + .../service/impl/UserServiceImpl.java | 73 +++++++++++++++- src/main/resources/application.properties | 7 +- 10 files changed, 278 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/educare/unitylend/controller/CommunityController.java create mode 100644 src/main/java/com/educare/unitylend/service/CommunityService.java 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..07a8ef7 --- /dev/null +++ b/src/main/java/com/educare/unitylend/controller/CommunityController.java @@ -0,0 +1,58 @@ +package com.educare.unitylend.controller; + +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.Community; +import com.educare.unitylend.model.User; +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 { + // Create the user + try { + communityService.createCommunity(community); + 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); + } + + } + +} diff --git a/src/main/java/com/educare/unitylend/controller/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index b0406b4..ac14836 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; @@ -21,7 +19,6 @@ 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 +27,42 @@ 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/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 4c57b4b..2e2ca4e 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,28 @@ @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 where password='pass123' ") + 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 (uuid_generate_v4(), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})") + void createUser(User user); + + @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename}, income = #{income} WHERE userid = #{userid}") + void updateUser(User user); + } diff --git a/src/main/java/com/educare/unitylend/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index d65f997..cae8cce 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -4,14 +4,13 @@ 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; } diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index 73bebc7..91ca2b3 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -4,7 +4,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Date; +import java.time.LocalDate; import java.util.UUID; @@ -12,14 +12,79 @@ @NoArgsConstructor @AllArgsConstructor public class User { - private UUID userID; + 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; + private String email; + private LocalDate dob; + private Integer income; + private Integer borrowingLimit; + private String officename; + private String collegeuniversity; + 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() { + System.out.println(name); + return name; + } + + public String getEmail() { + return email; + } + + public LocalDate getDob() { + return dob; + } + + public void setCollegeuniversity(String collegeuniversity) { + this.collegeuniversity = collegeuniversity; + } + + public UUID getUserid() { + return 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/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..bd964e3 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -12,7 +12,9 @@ public interface UserService { * @throws ServiceException : Throws if any exception occurs */ 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/impl/UserServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java index 288147c..2d8312a 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -1,6 +1,8 @@ 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.UserRepository; import com.educare.unitylend.model.User; import com.educare.unitylend.service.UserService; @@ -8,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Slf4j @@ -16,15 +19,17 @@ public class UserServiceImpl implements UserService { private UserRepository userRepository; - + private CommunityRepository communityRepository; + private UserCommunityController userCommunityController; @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 +45,68 @@ 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 str:matchingCommontags){ + if(!communityRepository.existsByCommontag(str)){ + + communityRepository.createCommunityUsingStrings(str,str); + } + } + + userRepository.createUser(newUser); + log.info("addeddd!!!!", newUser.getIncome()); + newUser.setBorrowingLimit(newUser.getIncome() / 2); + + log.info("addeddd!!!!", newUser.getBorrowingLimit()); + // userCommunityController.createUserCommunityMapping(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 { + // Your logic to validate and perform additional checks before updating + 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/resources/application.properties b/src/main/resources/application.properties index af09fad..371e31f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,8 @@ 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=prathyu123 spring.datasource.driver-class-name=org.postgresql.Driver + From 86d1fcb5cb97359fda62da54b798e6ee1e4fcd67 Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 03:36:09 +0530 Subject: [PATCH 03/11] Resolved Issue 9, 10 & 12 --- .../controller/UserCommunityController.java | 32 ++++++++++ .../unitylend/dao/CommunityRepository.java | 32 ++++++++++ .../dao/UserCommunityRepository.java | 16 +++++ .../service/impl/CommunityServiceImpl.java | 61 +++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 src/main/java/com/educare/unitylend/controller/UserCommunityController.java create mode 100644 src/main/java/com/educare/unitylend/dao/CommunityRepository.java create mode 100644 src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java create mode 100644 src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java 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/dao/CommunityRepository.java b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java new file mode 100644 index 0000000..769c24b --- /dev/null +++ b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java @@ -0,0 +1,32 @@ +package com.educare.unitylend.dao; + +import com.educare.unitylend.model.Community; +import com.educare.unitylend.model.User; +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); +} 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/service/impl/CommunityServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java new file mode 100644 index 0000000..89fce88 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java @@ -0,0 +1,61 @@ +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.model.User; +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); + System.out.println(communityName); + 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); + } + } + + + +} From 07d56357e5076501dc87c84f6b5c03747bce855d Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 16:25:34 +0530 Subject: [PATCH 04/11] Resolved Issue 9, 10 & 12 --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 371e31f..1040d25 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ server.port=8085 spring.datasource.url=jdbc:postgresql://localhost:5432/unitylend -spring.datasource.username=postgres -spring.datasource.password=prathyu123 +spring.datasource.username= +spring.datasource.password= spring.datasource.driver-class-name=org.postgresql.Driver From 72b2930940e7164b9013741cbded2268efe6a220 Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 19:06:30 +0530 Subject: [PATCH 05/11] Resolved Issue 9, 10 & 12 --- .../unitylend/controller/UserController.java | 32 +++++++-------- .../unitylend/dao/CommunityRepository.java | 5 +++ .../dao/UserCommunityRepository.java | 4 +- .../educare/unitylend/dao/UserRepository.java | 11 ++++- .../educare/unitylend/model/Community.java | 4 +- .../com/educare/unitylend/model/User.java | 22 ++++++++++ .../unitylend/service/UserService.java | 2 +- .../service/impl/UserServiceImpl.java | 40 +++++++++++++------ 8 files changed, 86 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/educare/unitylend/controller/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index ac14836..ab436aa 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -46,22 +46,22 @@ public ResponseEntity createUser(@RequestBody User user) throws Controll } - @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"); -} +// @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/dao/CommunityRepository.java b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java index 769c24b..a7e5cf0 100644 --- a/src/main/java/com/educare/unitylend/dao/CommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java @@ -8,6 +8,8 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.UUID; + @Mapper @Repository @@ -29,4 +31,7 @@ public interface CommunityRepository { @Select("SELECT commontag FROM community WHERE commontag = #{commontag}") String findByCommontag(String commontag); + + @Select("SELECT communityid FROM community WHERE communityname = #{name}") + UUID 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 index b3cec4e..9e0b398 100644 --- a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java @@ -6,11 +6,13 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Mapper @Repository public interface UserCommunityRepository { @Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})") - void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId); + void createUserCommunityMapping(@Param("userid") UUID userId, @Param("communityid") UUID communityId); } diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 2e2ca4e..8cf8d3c 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.UUID; @Mapper @Repository @@ -31,7 +32,13 @@ static String getUserForUserIdQuery(String userId){ @Insert("INSERT INTO tempuser (userid, password, name,email,dob,income,officename,collegeuniversity,locality) VALUES (uuid_generate_v4(), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})") void createUser(User user); - @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename}, income = #{income} WHERE userid = #{userid}") - void updateUser(User user); + @Select("SELECT userid FROM tempuser WHERE email = #{email}") + UUID settingID(@Param("email") String email); + + + +// @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename}, income = #{income} WHERE userid = #{userid}") +// void updateUser(User user); + } diff --git a/src/main/java/com/educare/unitylend/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index cae8cce..8e93de8 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -4,11 +4,13 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.UUID; + @Data @NoArgsConstructor @AllArgsConstructor public class Community { - private String communityid; + private UUID communityid; private String communityname; private String commontag; diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index 91ca2b3..f2c301b 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -60,7 +60,29 @@ public void setCollegeuniversity(String collegeuniversity) { this.collegeuniversity = collegeuniversity; } + public void setUserid(UUID userid) { + this.userid = 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 UUID getUserid() { + + System.out.println(userid); return userid; } diff --git a/src/main/java/com/educare/unitylend/service/UserService.java b/src/main/java/com/educare/unitylend/service/UserService.java index bd964e3..f7d96a5 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -12,7 +12,7 @@ public interface UserService { * @throws ServiceException : Throws if any exception occurs */ List getUsers() throws ServiceException; - void updateUser(User user) throws ServiceException; + //void updateUser(User user) throws ServiceException; void createUser(User user) throws ServiceException; /** 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 2d8312a..617fbd8 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -3,6 +3,7 @@ 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.model.User; import com.educare.unitylend.service.UserService; @@ -21,6 +22,7 @@ public class UserServiceImpl implements UserService { private UserRepository userRepository; private CommunityRepository communityRepository; private UserCommunityController userCommunityController; + private UserCommunityRepository userCommunityRepository; @Override public List getUsers() throws ServiceException { @@ -48,22 +50,34 @@ public User getUserByUserId(String userId) throws ServiceException { public void createUser(User newUser) throws ServiceException { + // System.out.println(newUser.getUserid()); List matchingCommontags = findMatchingCommontags(newUser); try { // Add any validation logic if needed before saving to the database for(String str:matchingCommontags){ - if(!communityRepository.existsByCommontag(str)){ + // System.out.println(str); + if(!communityRepository.existsByCommontag(str)) { - communityRepository.createCommunityUsingStrings(str,str); + communityRepository.createCommunityUsingStrings(str, str); } + } userRepository.createUser(newUser); + // newUser.setUserid(userRepository.settingID(newUser.getEmail())); log.info("addeddd!!!!", newUser.getIncome()); newUser.setBorrowingLimit(newUser.getIncome() / 2); log.info("addeddd!!!!", newUser.getBorrowingLimit()); - // userCommunityController.createUserCommunityMapping(newUser.getUserid(),); + + String collegeuni = newUser.getCollegeuniversity(); + // System.out.println("collegeuni "+collegeuni); +// if(collegeuni!=null){ +// System.out.println(newUser.getUserid()); +// System.out.println("commu id "+communityRepository.getCommunityIdByName(collegeuni)); +// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(),communityRepository.getCommunityIdByName(collegeuni)); +// } + } catch (Exception e) { log.error("Error encountered during user creation operation"); @@ -98,15 +112,15 @@ private List findMatchingCommontags(User user) { return matchingCommontags; } - public void updateUser(User user) throws ServiceException { - // Your logic to validate and perform additional checks before updating - 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); - } - } +// public void updateUser(User user) throws ServiceException { +// // Your logic to validate and perform additional checks before updating +// 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); +// } +// } } From 7de0820e5d8514db439c913473aadfcad440eab3 Mon Sep 17 00:00:00 2001 From: Prathyu2004 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 19:06:30 +0530 Subject: [PATCH 06/11] Resolved Issue 9, 10 & 12 --- .../unitylend/controller/UserController.java | 32 +++++++-------- .../unitylend/dao/CommunityRepository.java | 5 +++ .../dao/UserCommunityRepository.java | 4 +- .../educare/unitylend/dao/UserRepository.java | 11 ++++- .../educare/unitylend/model/Community.java | 4 +- .../com/educare/unitylend/model/User.java | 22 ++++++++++ .../unitylend/service/UserService.java | 2 +- .../service/impl/UserServiceImpl.java | 40 +++++++++++++------ 8 files changed, 86 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/educare/unitylend/controller/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index ac14836..ab436aa 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -46,22 +46,22 @@ public ResponseEntity createUser(@RequestBody User user) throws Controll } - @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"); -} +// @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/dao/CommunityRepository.java b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java index 769c24b..a7e5cf0 100644 --- a/src/main/java/com/educare/unitylend/dao/CommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java @@ -8,6 +8,8 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.UUID; + @Mapper @Repository @@ -29,4 +31,7 @@ public interface CommunityRepository { @Select("SELECT commontag FROM community WHERE commontag = #{commontag}") String findByCommontag(String commontag); + + @Select("SELECT communityid FROM community WHERE communityname = #{name}") + UUID 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 index b3cec4e..9e0b398 100644 --- a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java @@ -6,11 +6,13 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Mapper @Repository public interface UserCommunityRepository { @Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})") - void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId); + void createUserCommunityMapping(@Param("userid") UUID userId, @Param("communityid") UUID communityId); } diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 2e2ca4e..8cf8d3c 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.UUID; @Mapper @Repository @@ -31,7 +32,13 @@ static String getUserForUserIdQuery(String userId){ @Insert("INSERT INTO tempuser (userid, password, name,email,dob,income,officename,collegeuniversity,locality) VALUES (uuid_generate_v4(), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})") void createUser(User user); - @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename}, income = #{income} WHERE userid = #{userid}") - void updateUser(User user); + @Select("SELECT userid FROM tempuser WHERE email = #{email}") + UUID settingID(@Param("email") String email); + + + +// @Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename}, income = #{income} WHERE userid = #{userid}") +// void updateUser(User user); + } diff --git a/src/main/java/com/educare/unitylend/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index cae8cce..8e93de8 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -4,11 +4,13 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.UUID; + @Data @NoArgsConstructor @AllArgsConstructor public class Community { - private String communityid; + private UUID communityid; private String communityname; private String commontag; diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index 91ca2b3..f2c301b 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -60,7 +60,29 @@ public void setCollegeuniversity(String collegeuniversity) { this.collegeuniversity = collegeuniversity; } + public void setUserid(UUID userid) { + this.userid = 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 UUID getUserid() { + + System.out.println(userid); return userid; } diff --git a/src/main/java/com/educare/unitylend/service/UserService.java b/src/main/java/com/educare/unitylend/service/UserService.java index bd964e3..f7d96a5 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -12,7 +12,7 @@ public interface UserService { * @throws ServiceException : Throws if any exception occurs */ List getUsers() throws ServiceException; - void updateUser(User user) throws ServiceException; + //void updateUser(User user) throws ServiceException; void createUser(User user) throws ServiceException; /** 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 2d8312a..617fbd8 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -3,6 +3,7 @@ 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.model.User; import com.educare.unitylend.service.UserService; @@ -21,6 +22,7 @@ public class UserServiceImpl implements UserService { private UserRepository userRepository; private CommunityRepository communityRepository; private UserCommunityController userCommunityController; + private UserCommunityRepository userCommunityRepository; @Override public List getUsers() throws ServiceException { @@ -48,22 +50,34 @@ public User getUserByUserId(String userId) throws ServiceException { public void createUser(User newUser) throws ServiceException { + // System.out.println(newUser.getUserid()); List matchingCommontags = findMatchingCommontags(newUser); try { // Add any validation logic if needed before saving to the database for(String str:matchingCommontags){ - if(!communityRepository.existsByCommontag(str)){ + // System.out.println(str); + if(!communityRepository.existsByCommontag(str)) { - communityRepository.createCommunityUsingStrings(str,str); + communityRepository.createCommunityUsingStrings(str, str); } + } userRepository.createUser(newUser); + // newUser.setUserid(userRepository.settingID(newUser.getEmail())); log.info("addeddd!!!!", newUser.getIncome()); newUser.setBorrowingLimit(newUser.getIncome() / 2); log.info("addeddd!!!!", newUser.getBorrowingLimit()); - // userCommunityController.createUserCommunityMapping(newUser.getUserid(),); + + String collegeuni = newUser.getCollegeuniversity(); + // System.out.println("collegeuni "+collegeuni); +// if(collegeuni!=null){ +// System.out.println(newUser.getUserid()); +// System.out.println("commu id "+communityRepository.getCommunityIdByName(collegeuni)); +// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(),communityRepository.getCommunityIdByName(collegeuni)); +// } + } catch (Exception e) { log.error("Error encountered during user creation operation"); @@ -98,15 +112,15 @@ private List findMatchingCommontags(User user) { return matchingCommontags; } - public void updateUser(User user) throws ServiceException { - // Your logic to validate and perform additional checks before updating - 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); - } - } +// public void updateUser(User user) throws ServiceException { +// // Your logic to validate and perform additional checks before updating +// 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); +// } +// } } From cb66107885929e90e7b71691760a90d1092fffe6 Mon Sep 17 00:00:00 2001 From: Prathyusha5c0 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 21:10:27 +0530 Subject: [PATCH 07/11] Resolved Issue 9, 10 & 12 --- .../com/educare/unitylend/controller/CommunityController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/educare/unitylend/controller/CommunityController.java b/src/main/java/com/educare/unitylend/controller/CommunityController.java index 07a8ef7..29c6d39 100644 --- a/src/main/java/com/educare/unitylend/controller/CommunityController.java +++ b/src/main/java/com/educare/unitylend/controller/CommunityController.java @@ -44,7 +44,6 @@ public String getCommunityWithTag(@RequestParam String commonTag) throws Control @PostMapping("/create-community") public ResponseEntity createNewCommunity(@RequestBody Community community) throws ControllerException { - // Create the user try { communityService.createCommunity(community); return ResponseEntity.ok("succcesss!!!"); From 046509a12502281e6a19ec8f083d8d51943ae3a2 Mon Sep 17 00:00:00 2001 From: Prathyusha5c0 <21b01a05c0@svecw.edu.in> Date: Tue, 27 Feb 2024 21:10:27 +0530 Subject: [PATCH 08/11] Resolved Issues 9, 10 & 12 --- .../controller/CommunityController.java | 4 +- .../unitylend/controller/UserController.java | 31 ++++++----- .../unitylend/dao/CommunityRepository.java | 4 +- .../dao/UserCommunityRepository.java | 4 +- .../educare/unitylend/dao/UserRepository.java | 13 +++-- .../educare/unitylend/model/Community.java | 26 ++++++++-- .../com/educare/unitylend/model/User.java | 18 +++---- .../unitylend/service/UserService.java | 3 +- .../service/impl/CommunityServiceImpl.java | 6 +-- .../service/impl/UserServiceImpl.java | 51 ++++++++++--------- 10 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/educare/unitylend/controller/CommunityController.java b/src/main/java/com/educare/unitylend/controller/CommunityController.java index 07a8ef7..1a5c229 100644 --- a/src/main/java/com/educare/unitylend/controller/CommunityController.java +++ b/src/main/java/com/educare/unitylend/controller/CommunityController.java @@ -2,7 +2,6 @@ import com.educare.unitylend.Exception.ControllerException; import com.educare.unitylend.model.Community; -import com.educare.unitylend.model.User; import com.educare.unitylend.service.CommunityService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -44,10 +43,9 @@ public String getCommunityWithTag(@RequestParam String commonTag) throws Control @PostMapping("/create-community") public ResponseEntity createNewCommunity(@RequestBody Community community) throws ControllerException { - // Create the user try { communityService.createCommunity(community); - return ResponseEntity.ok("succcesss!!!"); + 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/UserController.java b/src/main/java/com/educare/unitylend/controller/UserController.java index ab436aa..9ca27fd 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -46,22 +46,21 @@ public ResponseEntity createUser(@RequestBody User user) throws Controll } -// @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"); -//} + @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/dao/CommunityRepository.java b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java index a7e5cf0..c97d27e 100644 --- a/src/main/java/com/educare/unitylend/dao/CommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/CommunityRepository.java @@ -1,14 +1,12 @@ package com.educare.unitylend.dao; import com.educare.unitylend.model.Community; -import com.educare.unitylend.model.User; 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; -import java.util.UUID; @Mapper @Repository @@ -33,5 +31,5 @@ public interface CommunityRepository { String findByCommontag(String commontag); @Select("SELECT communityid FROM community WHERE communityname = #{name}") - UUID getCommunityIdByName(String 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 index 9e0b398..b3cec4e 100644 --- a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java @@ -6,13 +6,11 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; -import java.util.UUID; - @Mapper @Repository public interface UserCommunityRepository { @Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})") - void createUserCommunityMapping(@Param("userid") UUID userId, @Param("communityid") UUID 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 8cf8d3c..18da957 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -5,7 +5,6 @@ import org.springframework.stereotype.Repository; import java.util.List; -import java.util.UUID; @Mapper @Repository @@ -22,23 +21,23 @@ static String getUserForUserIdQuery(String userId){ return sqlQueryBuilder.toString(); } - @Select("select * from tempuser where password='pass123' ") + @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 (uuid_generate_v4(), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})") + @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}") - UUID settingID(@Param("email") String email); + @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}, income = #{income} WHERE userid = #{userid}") -// void updateUser(User user); + @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/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index 8e93de8..022b45e 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -4,15 +4,35 @@ import lombok.Data; import lombok.NoArgsConstructor; -import java.util.UUID; - @Data @NoArgsConstructor @AllArgsConstructor public class Community { - private UUID communityid; + 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 f2c301b..e6cd202 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -5,14 +5,13 @@ import lombok.NoArgsConstructor; import java.time.LocalDate; -import java.util.UUID; @Data @NoArgsConstructor @AllArgsConstructor public class User { - private UUID userid; + private String userid; private String password; private String name; private String email; @@ -44,7 +43,6 @@ public String getPassword() { } public String getName() { - System.out.println(name); return name; } @@ -60,8 +58,8 @@ public void setCollegeuniversity(String collegeuniversity) { this.collegeuniversity = collegeuniversity; } - public void setUserid(UUID userid) { - this.userid = userid; + public String getUserid() { + return userid; } public void setPassword(String password) { @@ -80,10 +78,8 @@ public void setDob(LocalDate dob) { this.dob = dob; } - public UUID getUserid() { - - System.out.println(userid); - return userid; + public void setUserid(String userid) { + this.userid = userid; } public String getLocality() { @@ -95,7 +91,7 @@ public void setLocality(String locality) { } public void setIncome(Integer income) { - System.out.println(income); + // System.out.println(income); this.income = income; } @@ -105,7 +101,7 @@ public Integer getBorrowingLimit() { public void setBorrowingLimit(Integer borrowingLimit) { this.borrowingLimit = borrowingLimit; - System.out.println(borrowingLimit); + // System.out.println(borrowingLimit); } diff --git a/src/main/java/com/educare/unitylend/service/UserService.java b/src/main/java/com/educare/unitylend/service/UserService.java index f7d96a5..9776881 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -12,7 +12,8 @@ public interface UserService { * @throws ServiceException : Throws if any exception occurs */ List getUsers() throws ServiceException; - //void updateUser(User user) throws ServiceException; + + void updateUser(User user) throws ServiceException; void createUser(User user) 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 index 89fce88..7822985 100644 --- a/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/CommunityServiceImpl.java @@ -3,7 +3,6 @@ import com.educare.unitylend.Exception.ServiceException; import com.educare.unitylend.dao.CommunityRepository; import com.educare.unitylend.model.Community; -import com.educare.unitylend.model.User; import com.educare.unitylend.service.CommunityService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,7 +22,7 @@ public List getCommunities() throws ServiceException { // log.info("userList ",userList); return communityList; } catch (Exception e) { - //log.error("Error encountered during user fetching operation"); + log.error("Error encountered during user fetching operation"); throw new ServiceException("Error encountered during user fetch operation", e); } } @@ -33,10 +32,9 @@ public String getCommunityName(String communityTag) throws ServiceException { try { String communityName= communityRepository.getCommunity(communityTag); // log.info("userList ",userList); - System.out.println(communityName); return communityName; } catch (Exception e) { - //log.error("Error encountered during user fetching operation"); + 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/UserServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java index 617fbd8..1e08ad3 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -50,33 +50,36 @@ public User getUserByUserId(String userId) throws ServiceException { public void createUser(User newUser) throws ServiceException { - // System.out.println(newUser.getUserid()); List matchingCommontags = findMatchingCommontags(newUser); try { // Add any validation logic if needed before saving to the database - for(String str:matchingCommontags){ - // System.out.println(str); - if(!communityRepository.existsByCommontag(str)) { + for (String tag : matchingCommontags) { + if (!communityRepository.existsByCommontag(tag)) { - communityRepository.createCommunityUsingStrings(str, str); + communityRepository.createCommunityUsingStrings(tag, tag); } } userRepository.createUser(newUser); - // newUser.setUserid(userRepository.settingID(newUser.getEmail())); - log.info("addeddd!!!!", newUser.getIncome()); + newUser.setUserid(userRepository.settingID(newUser.getEmail())); + // log.info("addeddd!!!!", newUser.getIncome()); newUser.setBorrowingLimit(newUser.getIncome() / 2); - log.info("addeddd!!!!", newUser.getBorrowingLimit()); + // log.info("addeddd!!!!", newUser.getBorrowingLimit()); - String collegeuni = newUser.getCollegeuniversity(); - // System.out.println("collegeuni "+collegeuni); -// if(collegeuni!=null){ -// System.out.println(newUser.getUserid()); -// System.out.println("commu id "+communityRepository.getCommunityIdByName(collegeuni)); -// userCommunityRepository.createUserCommunityMapping(newUser.getUserid(),communityRepository.getCommunityIdByName(collegeuni)); -// } + String collegeUni = newUser.getCollegeuniversity(); + String office = newUser.getOfficename(); + String locality = newUser.getLocality(); + if (collegeUni != null) { + userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(collegeUni)); + } + if (office != null) { + userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(office)); + } + if (locality != null) { + userCommunityRepository.createUserCommunityMapping(newUser.getUserid(), communityRepository.getCommunityIdByName(locality)); + } } catch (Exception e) { @@ -112,15 +115,13 @@ private List findMatchingCommontags(User user) { return matchingCommontags; } -// public void updateUser(User user) throws ServiceException { -// // Your logic to validate and perform additional checks before updating -// 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); -// } -// } + 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); + } + } } From faf9a1788a4853e809a5874459aad86407c865ce Mon Sep 17 00:00:00 2001 From: Prathyusha5c0 <21b01a05c0@svecw.edu.in> Date: Fri, 1 Mar 2024 15:16:26 +0530 Subject: [PATCH 09/11] Get communities associated with a given userId --- .../controller/CommunityController.java | 42 +++++++------ .../controller/UserCommunityController.java | 25 ++++---- .../unitylend/controller/UserController.java | 61 ++++++++++++++++--- .../dao/UserCommunityRepository.java | 7 +++ .../educare/unitylend/dao/UserRepository.java | 31 ++++++---- .../unitylend/model/BorrowRequest.java | 2 +- .../unitylend/model/LendingHistory.java | 2 +- .../model/Repayment_Transaction.java | 8 +-- .../com/educare/unitylend/model/User.java | 9 +++ .../com/educare/unitylend/model/Wallet.java | 4 +- .../unitylend/service/CommunityService.java | 1 + .../service/UserCommunityService.java | 10 +++ .../unitylend/service/UserService.java | 2 +- .../impl/UserCommunityServiceImpl.java | 29 +++++++++ .../service/impl/UserServiceImpl.java | 17 ++++++ src/main/resources/application.properties | 4 +- src/main/resources/scratch.sql | 3 + 17 files changed, 197 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/educare/unitylend/service/UserCommunityService.java create mode 100644 src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java diff --git a/src/main/java/com/educare/unitylend/controller/CommunityController.java b/src/main/java/com/educare/unitylend/controller/CommunityController.java index 1a5c229..e0c40f0 100644 --- a/src/main/java/com/educare/unitylend/controller/CommunityController.java +++ b/src/main/java/com/educare/unitylend/controller/CommunityController.java @@ -1,10 +1,12 @@ package com.educare.unitylend.controller; import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.Exception.ServiceException; import com.educare.unitylend.model.Community; import com.educare.unitylend.service.CommunityService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -14,43 +16,49 @@ @AllArgsConstructor @RestController @RequestMapping("/community") - public class CommunityController extends BaseController { CommunityService communityService; @GetMapping("all-communities") - public List getAllCommunities() throws ControllerException { - + public ResponseEntity 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); + + if (communityList.isEmpty()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found"); + } + + return ResponseEntity.ok(communityList); + } catch (ServiceException e) { + log.error("Error encountered in getting the communities", e); + throw new ControllerException("Error encountered in getting the communities", e); } } + @GetMapping("get-community-by-tag") - public String getCommunityWithTag(@RequestParam String commonTag) throws ControllerException { + public ResponseEntity 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"); + + if (communityName == null || communityName.isEmpty()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found"); + } + + return ResponseEntity.ok(communityName); + } catch (ServiceException e) { + log.error("Error encountered in getting the community by tag", e); 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); + } catch (ServiceException e) { + log.error("Error encountered in creating the community", e); + throw new ControllerException("Error encountered in creating the community", e); } - } - } diff --git a/src/main/java/com/educare/unitylend/controller/UserCommunityController.java b/src/main/java/com/educare/unitylend/controller/UserCommunityController.java index a4b577f..8b48b14 100644 --- a/src/main/java/com/educare/unitylend/controller/UserCommunityController.java +++ b/src/main/java/com/educare/unitylend/controller/UserCommunityController.java @@ -1,10 +1,12 @@ package com.educare.unitylend.controller; import com.educare.unitylend.Exception.ControllerException; -import com.educare.unitylend.model.User; +import com.educare.unitylend.service.UserCommunityService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; 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; @@ -16,17 +18,18 @@ @RequestMapping("/usercommunity") public class UserCommunityController { +private UserCommunityService usercommunityService; + @GetMapping("/{userId}") + public ResponseEntity> getAllCommunities(@PathVariable String userId) throws ControllerException { + try { + List communityList = usercommunityService.getCommunitiesByUserId(userId); + return ResponseEntity.ok(communityList); + } catch (Exception e) { + log.error("Error encountered in getting the communities for user with ID: {}", userId, e); + throw new ControllerException("Error encountered in getting the communities", e); + } + } -// @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 9ca27fd..7793631 100644 --- a/src/main/java/com/educare/unitylend/controller/UserController.java +++ b/src/main/java/com/educare/unitylend/controller/UserController.java @@ -1,10 +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.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -23,23 +25,27 @@ public class UserController extends BaseController { * @throws ControllerException : Exception to be thrown from controller in case of any exception */ @GetMapping("all-users") - public List getAllUsers() throws ControllerException { + public ResponseEntity getAllUsers() throws ControllerException { try { List userList = userService.getUsers(); - return userList; - } catch (Exception e) { - log.error("Error encountered in getting the users"); + if (userList.isEmpty()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found"); + } + return ResponseEntity.ok(userList); + } catch (ServiceException e) { + log.error("Error encountered in getting the users", e); throw new ControllerException("Error encountered in getting the users", e); } } + @PostMapping("/create-user") - public ResponseEntity createUser(@RequestBody User user) throws ControllerException { + public ResponseEntity createUser(@RequestBody User user) throws ControllerException{ // Create the user try { userService.createUser(user); return ResponseEntity.ok("succcesss!!!"); - } catch (Exception e) { + } catch (ServiceException e) { log.error("Error encountered in getting the users"); throw new ControllerException("Error encountered in getting the users", e); } @@ -50,17 +56,56 @@ public ResponseEntity createUser(@RequestBody User user) throws Controll public ResponseEntity updateUser(@PathVariable String userId, @RequestBody User updatedUser) throws ControllerException { // Set the userId in the updatedUser object updatedUser.setUserid(userId); - + System.out.println(updatedUser); // Validate and update the user try { userService.updateUser(updatedUser); - } catch (Exception e) { + } catch (ServiceException 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"); } + @GetMapping("/{userId}/get-info") + public ResponseEntity getUserByUserId(@PathVariable String userId) throws ControllerException{ + try { + if (userId == null || userId.isEmpty()) { + return ResponseEntity.badRequest().build(); + } + + User user = userService.getUserByUserId(userId); + + if (user != null) { + return ResponseEntity.ok(user); + } else { + return ResponseEntity.notFound().build(); + } + } catch (ServiceException e) { + // Log the exception or handle it as needed + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @PutMapping("/{userId}/inactive") + public ResponseEntity deactivateUser(@PathVariable String userId) { + try { + if (userId == null || userId.isEmpty()) { + return ResponseEntity.badRequest().build(); + } + boolean updated = userService.markUserAsInactive(userId); + + if (updated) { + return ResponseEntity.ok("User marked as inactive successfully"); + } else { + return ResponseEntity.notFound().build(); + } + } catch (ServiceException e) { + // Log the exception or handle it as needed + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + } diff --git a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java index b3cec4e..33bc46c 100644 --- a/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserCommunityRepository.java @@ -4,8 +4,11 @@ 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 java.util.List; + @Mapper @Repository public interface UserCommunityRepository { @@ -13,4 +16,8 @@ public interface UserCommunityRepository { void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId); + @Select("SELECT c.CommunityName FROM Community c JOIN UserCommunity uc ON c.CommunityId = uc.CommunityId WHERE uc.UserId = #{userId}") + List findCommunityNamesByUserId(@Param("userId") String userId); + + } diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 18da957..713731a 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -10,34 +10,39 @@ @Repository public interface UserRepository { - static String getUserForUserIdQuery(String userId){ - StringBuilder sqlQueryBuilder = new StringBuilder(); - - 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(); - } +// static String getUserForUserIdQuery(String userId){ +// StringBuilder sqlQueryBuilder = new StringBuilder(); +// +// sqlQueryBuilder.append("select userid as userID, password, name,email,dob,income,officename,collegeuniversity,locality,isactive 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); +// @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 * FROM tempuser WHERE userid = #{userid}") + User getUserForUserId(String userId); @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}") + @Update("UPDATE tempuser SET name = #{name}, password = #{password}, email = #{email}, locality = #{locality}, officename = #{officename}, collegeuniversity = #{collegeuniversity}, income = #{income}, isActive = #{isActive} WHERE userid = #{userid}") void updateUser(User user); + @Update("UPDATE tempuser SET isActive = #{isActive} WHERE userid = #{userid}") + void inactivatingUser(User user); + } diff --git a/src/main/java/com/educare/unitylend/model/BorrowRequest.java b/src/main/java/com/educare/unitylend/model/BorrowRequest.java index 634e6a3..3aeabd6 100644 --- a/src/main/java/com/educare/unitylend/model/BorrowRequest.java +++ b/src/main/java/com/educare/unitylend/model/BorrowRequest.java @@ -12,7 +12,7 @@ @NoArgsConstructor @AllArgsConstructor public class BorrowRequest { - private UUID requestId; + private String requestId; private User borrower; private Community community; private String returnPeriod; diff --git a/src/main/java/com/educare/unitylend/model/LendingHistory.java b/src/main/java/com/educare/unitylend/model/LendingHistory.java index 6c1b230..c937d02 100644 --- a/src/main/java/com/educare/unitylend/model/LendingHistory.java +++ b/src/main/java/com/educare/unitylend/model/LendingHistory.java @@ -12,7 +12,7 @@ @NoArgsConstructor @AllArgsConstructor public class LendingHistory { - private UUID lendTransactionId; + private String lendTransactionId; private User lender; private User borrower; private BorrowRequest borrowRequest; diff --git a/src/main/java/com/educare/unitylend/model/Repayment_Transaction.java b/src/main/java/com/educare/unitylend/model/Repayment_Transaction.java index 6c2e2ec..64f1466 100644 --- a/src/main/java/com/educare/unitylend/model/Repayment_Transaction.java +++ b/src/main/java/com/educare/unitylend/model/Repayment_Transaction.java @@ -11,10 +11,10 @@ @NoArgsConstructor @AllArgsConstructor public class Repayment_Transaction { - private UUID RepayTransactionId; - private UUID PayerId; - private UUID PayeeId; - private UUID RequestId; + private String RepayTransactionId; + private String PayerId; + private String PayeeId; + private String RequestId; private Float Amount; private Date Timestamp; } diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index e6cd202..b191a6b 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -21,6 +21,15 @@ public class User { private String officename; private String collegeuniversity; private String locality; + private boolean isActive; + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean active) { + isActive = active; + } public Integer getIncome() { return income; diff --git a/src/main/java/com/educare/unitylend/model/Wallet.java b/src/main/java/com/educare/unitylend/model/Wallet.java index da231a0..6bfbb8c 100644 --- a/src/main/java/com/educare/unitylend/model/Wallet.java +++ b/src/main/java/com/educare/unitylend/model/Wallet.java @@ -10,7 +10,7 @@ @NoArgsConstructor @AllArgsConstructor public class Wallet { - private UUID Wallet; - private UUID userId; + private String Walletid; + private Float Balance; } diff --git a/src/main/java/com/educare/unitylend/service/CommunityService.java b/src/main/java/com/educare/unitylend/service/CommunityService.java index f841e05..291f6c9 100644 --- a/src/main/java/com/educare/unitylend/service/CommunityService.java +++ b/src/main/java/com/educare/unitylend/service/CommunityService.java @@ -10,4 +10,5 @@ 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/UserCommunityService.java b/src/main/java/com/educare/unitylend/service/UserCommunityService.java new file mode 100644 index 0000000..67fc9d3 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/UserCommunityService.java @@ -0,0 +1,10 @@ +package com.educare.unitylend.service; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.User; + +import java.util.List; + +public interface UserCommunityService { + List getCommunitiesByUserId(String userId) 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 9776881..3034b37 100644 --- a/src/main/java/com/educare/unitylend/service/UserService.java +++ b/src/main/java/com/educare/unitylend/service/UserService.java @@ -14,7 +14,7 @@ public interface UserService { List getUsers() throws ServiceException; void updateUser(User user) throws ServiceException; - + boolean markUserAsInactive(String userId) throws ServiceException; void createUser(User user) throws ServiceException; /** * @param userId : Uniquely identifies a user diff --git a/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java new file mode 100644 index 0000000..dce7f45 --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/impl/UserCommunityServiceImpl.java @@ -0,0 +1,29 @@ +package com.educare.unitylend.service.impl; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.UserCommunityRepository; +import com.educare.unitylend.model.User; +import com.educare.unitylend.service.UserCommunityService; +import com.educare.unitylend.service.UserService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@AllArgsConstructor +@Service +public class UserCommunityServiceImpl implements UserCommunityService { + private UserCommunityRepository userCommunityRepository; + public List getCommunitiesByUserId(String userId) throws ServiceException{ + try { + List communityNames = userCommunityRepository.findCommunityNamesByUserId(userId); + // log.info("communityNames: ", 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/java/com/educare/unitylend/service/impl/UserServiceImpl.java b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java index 1e08ad3..50a9383 100644 --- a/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/UserServiceImpl.java @@ -117,11 +117,28 @@ private List findMatchingCommontags(User user) { public void updateUser(User user) throws ServiceException { try { + System.out.println(user); userRepository.updateUser(user); + } catch (Exception e) { log.error("Error encountered during user fetching operation"); throw new ServiceException("Error encountered during user fetch operation", e); } } + public boolean markUserAsInactive(String userId) throws ServiceException { + try { + User user = userRepository.getUserForUserId(userId); + if (user != null) { + user.setActive(false); + userRepository.inactivatingUser(user); + return true; + } else { + return false; + } + } catch (Exception e) { + throw new ServiceException("Error marking user as inactive", e); + } + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1040d25..371e31f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ server.port=8085 spring.datasource.url=jdbc:postgresql://localhost:5432/unitylend -spring.datasource.username= -spring.datasource.password= +spring.datasource.username=postgres +spring.datasource.password=prathyu123 spring.datasource.driver-class-name=org.postgresql.Driver diff --git a/src/main/resources/scratch.sql b/src/main/resources/scratch.sql index ea13d69..e4ce229 100644 --- a/src/main/resources/scratch.sql +++ b/src/main/resources/scratch.sql @@ -1353,3 +1353,6 @@ SELECT FROM "User" u; +alter table "TempUser" rename to "tempuser"; + + From 1c8facd493cdb708e9f12d3c14c86511cf9d4fda Mon Sep 17 00:00:00 2001 From: Vani Date: Mon, 4 Mar 2024 19:59:44 +0530 Subject: [PATCH 10/11] added-borrow-request-features --- .../controller/BorrowRequestController.java | 64 +++++++++++++++++++ .../dao/BorrowRequestRepository.java | 21 ++++++ .../educare/unitylend/dao/UserRepository.java | 3 + .../unitylend/model/BorrowRequest.java | 23 +++++-- .../service/BorrowRequestService.java | 13 ++++ .../impl/BorrowRequestServiceImpl.java | 55 ++++++++++++++++ src/main/resources/application.properties | 2 +- 7 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/educare/unitylend/controller/BorrowRequestController.java create mode 100644 src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java create mode 100644 src/main/java/com/educare/unitylend/service/BorrowRequestService.java create mode 100644 src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java diff --git a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java new file mode 100644 index 0000000..fad502e --- /dev/null +++ b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java @@ -0,0 +1,64 @@ +package com.educare.unitylend.controller; + +import com.educare.unitylend.Exception.ControllerException; +import com.educare.unitylend.model.BorrowRequest; +import com.educare.unitylend.service.BorrowRequestService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@AllArgsConstructor +@RestController +@RequestMapping("/borrow-request") +public class BorrowRequestController extends BaseController{ + BorrowRequestService borrowRequestService; + @GetMapping("/{userId}") + public ResponseEntity> getAllCommunities(@PathVariable String userId) throws ControllerException { + try { + if (userId == null || userId.isEmpty()) { + return ResponseEntity.badRequest().body(List.of("User ID cannot be null or empty")); + } + + List communityList = borrowRequestService.getRequestedCommunitiesByUserId(userId); + + if (communityList == null || communityList.isEmpty()) { + return ResponseEntity.notFound().build(); + } + + return ResponseEntity.ok(communityList); + } catch (Exception e) { + log.error("Error encountered in getting the communities for user with ID: {}", userId, e); + throw new ControllerException("Error encountered in getting the communities", e); + } + } + + @PostMapping("/request") + public ResponseEntity raiseBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ControllerException { + try { + String userId = borrowRequest.getBorrowerid(); + + if (userId == null || userId.isEmpty()) { + return ResponseEntity.badRequest().body("User ID cannot be null or empty"); + } + + boolean isBorrowRequestSuccessful = borrowRequestService.raiseBorrowRequestForUserid(userId,borrowRequest); + + if (isBorrowRequestSuccessful) { + return ResponseEntity.ok("Raised Borrow Request"); + } else { + return ResponseEntity.ok("Cannot make borrow request as your EMI is greater than monthly salary"); + } + } catch (Exception e) { + log.error("Error encountered in raising borrow request for user with ID: {}", borrowRequest.getBorrower(), e); + throw new ControllerException("Error encountered in getting the communities", e); + } + } + + + + +} \ No newline at end of file diff --git a/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java new file mode 100644 index 0000000..f584593 --- /dev/null +++ b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java @@ -0,0 +1,21 @@ +package com.educare.unitylend.dao; + +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.util.List; + +@Mapper +@Repository +public interface BorrowRequestRepository { + + @Select("SELECT Community.CommunityName " + + "FROM Borrow_Request " + + "JOIN Community ON Borrow_Request.CommunityID = Community.CommunityId " + + "WHERE Borrow_Request.BorrowerID = #{userId}") + List getBorrowRequestesByUserInCommunities(@Param("userId") String userId); + + +} diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 713731a..561db26 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -45,4 +45,7 @@ public interface UserRepository { @Update("UPDATE tempuser SET isActive = #{isActive} WHERE userid = #{userid}") void inactivatingUser(User user); + @Select("SELECT income FROM tempuser WHERE userid = #{userid}") + Integer getIncome(@Param("userid") String userid); + } diff --git a/src/main/java/com/educare/unitylend/model/BorrowRequest.java b/src/main/java/com/educare/unitylend/model/BorrowRequest.java index 3aeabd6..25bffb1 100644 --- a/src/main/java/com/educare/unitylend/model/BorrowRequest.java +++ b/src/main/java/com/educare/unitylend/model/BorrowRequest.java @@ -1,8 +1,6 @@ package com.educare.unitylend.model; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -12,12 +10,27 @@ @NoArgsConstructor @AllArgsConstructor public class BorrowRequest { + @Getter @Setter private String requestId; + + @Getter @Setter private User borrower; + + @Getter @Setter private Community community; - private String returnPeriod; + + @Getter private String returnPeriod; + + @Getter @Setter private String status; + + @Getter @Setter private LocalDateTime timestamp; + private BigDecimal collectedAmount; - private BigDecimal targetAmount; + @Getter private BigDecimal targetAmount; + + public String getBorrowerid() { + return borrower.getUserid(); + } } diff --git a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java new file mode 100644 index 0000000..2568bda --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java @@ -0,0 +1,13 @@ +package com.educare.unitylend.service; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.model.BorrowRequest; + +import java.util.List; + +public interface BorrowRequestService { + + List getRequestedCommunitiesByUserId(String userId) throws ServiceException; + + boolean raiseBorrowRequestForUserid(String userId, BorrowRequest borrowRequest) 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 new file mode 100644 index 0000000..cc067bc --- /dev/null +++ b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java @@ -0,0 +1,55 @@ +package com.educare.unitylend.service.impl; + +import com.educare.unitylend.Exception.ServiceException; +import com.educare.unitylend.dao.BorrowRequestRepository; +import com.educare.unitylend.dao.UserRepository; +import com.educare.unitylend.model.BorrowRequest; +import com.educare.unitylend.model.User; +import com.educare.unitylend.service.BorrowRequestService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; + +@Slf4j +@AllArgsConstructor +@Service +public class BorrowRequestServiceImpl implements BorrowRequestService { + private UserRepository userRepository; + private BorrowRequestRepository borrowRequestRepository; + public List getRequestedCommunitiesByUserId(String userId) throws ServiceException{ + List communities=borrowRequestRepository.getBorrowRequestesByUserInCommunities(userId); + System.out.println(communities); + return communities; + } + public boolean raiseBorrowRequestForUserid(String userId, BorrowRequest borrowRequest) throws ServiceException { + try { + // Assuming returnPeriod is in days + BigDecimal monthlyInterestRate = new BigDecimal("50.0").divide(new BigDecimal(12 * 100), 10, RoundingMode.HALF_UP); + BigDecimal loanTenureMonths = new BigDecimal(borrowRequest.getReturnPeriod()).multiply(new BigDecimal("30.44")); + double pow = Math.pow(1 + monthlyInterestRate.doubleValue(), loanTenureMonths.doubleValue()); + BigDecimal emiNumerator = borrowRequest.getTargetAmount() + .multiply(new BigDecimal(pow)).multiply(new BigDecimal(50)); + + + BigDecimal emiDenominator = new BigDecimal(pow - 1); + + BigDecimal emi = emiNumerator.divide(emiDenominator, 2, RoundingMode.HALF_UP); + // BigDecimal emi =borrowRequest.getTargetAmount().divide(new BigDecimal(borrowRequest.getReturnPeriod())); + if (emi.compareTo(new BigDecimal(userRepository.getIncome(userId)).divide(new BigDecimal(2), 2, RoundingMode.HALF_UP)) <0) { + return false; + } + return true; + + } catch (Exception e) { + throw new ServiceException("Error in calculating EMI", e); + } + } + + + +} + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 371e31f..1bee198 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,6 +3,6 @@ server.port=8085 spring.datasource.url=jdbc:postgresql://localhost:5432/unitylend spring.datasource.username=postgres -spring.datasource.password=prathyu123 +spring.datasource.password=UnityLend spring.datasource.driver-class-name=org.postgresql.Driver From 0408170e157d40d5abdc19fe7ffdc8ca7242fa49 Mon Sep 17 00:00:00 2001 From: Vani Date: Fri, 8 Mar 2024 18:15:20 +0530 Subject: [PATCH 11/11] added-borrow-request-features --- .../controller/BorrowRequestController.java | 5 +++-- .../unitylend/dao/BorrowRequestRepository.java | 9 +++++++-- .../educare/unitylend/dao/UserRepository.java | 11 +---------- .../educare/unitylend/model/BorrowRequest.java | 2 +- .../com/educare/unitylend/model/Community.java | 3 ++- .../java/com/educare/unitylend/model/User.java | 18 +++++++++--------- .../service/BorrowRequestService.java | 4 +++- .../service/impl/BorrowRequestServiceImpl.java | 8 ++++++-- 8 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java index fad502e..659e9df 100644 --- a/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java +++ b/src/main/java/com/educare/unitylend/controller/BorrowRequestController.java @@ -39,15 +39,16 @@ public ResponseEntity> getAllCommunities(@PathVariable String userI @PostMapping("/request") public ResponseEntity raiseBorrowRequest(@RequestBody BorrowRequest borrowRequest) throws ControllerException { try { - String userId = borrowRequest.getBorrowerid(); + String userId = borrowRequest.getBorrowerId(); if (userId == null || userId.isEmpty()) { return ResponseEntity.badRequest().body("User ID cannot be null or empty"); } - boolean isBorrowRequestSuccessful = borrowRequestService.raiseBorrowRequestForUserid(userId,borrowRequest); + boolean isBorrowRequestSuccessful = borrowRequestService.raiseBorrowRequestByUserId(userId,borrowRequest); if (isBorrowRequestSuccessful) { + borrowRequestService.createBorrowRequest(borrowRequest); return ResponseEntity.ok("Raised Borrow Request"); } else { return ResponseEntity.ok("Cannot make borrow request as your EMI is greater than monthly salary"); diff --git a/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java index f584593..2d310c5 100644 --- a/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java +++ b/src/main/java/com/educare/unitylend/dao/BorrowRequestRepository.java @@ -1,5 +1,7 @@ package com.educare.unitylend.dao; +import com.educare.unitylend.model.BorrowRequest; +import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -14,8 +16,11 @@ public interface BorrowRequestRepository { @Select("SELECT Community.CommunityName " + "FROM Borrow_Request " + "JOIN Community ON Borrow_Request.CommunityID = Community.CommunityId " + - "WHERE Borrow_Request.BorrowerID = #{userId}") - List getBorrowRequestesByUserInCommunities(@Param("userId") String userId); + "WHERE Borrow_Request.BorrowerId = #{userId}") + List getBorrowRequestByUserId(@Param("userId") String userId); + @Insert("INSERT INTO Borrow_Request (RequestID, BorrowerID, CommunityID, ReturnPeriod, Status, TargetAmount) " + + "VALUES (uuid_generate_v4(), #{borrowRequest.borrowerId}, #{borrowRequest.community.communityid}, CAST (#{borrowRequest.returnPeriod} AS INTEGER), #{borrowRequest.status}, #{borrowRequest.targetAmount})") + void createBorrowRequest(@Param("borrowRequest") BorrowRequest borrowRequest); } diff --git a/src/main/java/com/educare/unitylend/dao/UserRepository.java b/src/main/java/com/educare/unitylend/dao/UserRepository.java index 561db26..94abbc7 100644 --- a/src/main/java/com/educare/unitylend/dao/UserRepository.java +++ b/src/main/java/com/educare/unitylend/dao/UserRepository.java @@ -10,16 +10,7 @@ @Repository public interface UserRepository { -// static String getUserForUserIdQuery(String userId){ -// StringBuilder sqlQueryBuilder = new StringBuilder(); -// -// sqlQueryBuilder.append("select userid as userID, password, name,email,dob,income,officename,collegeuniversity,locality,isactive from User where 1=1 "); -// if(userId != null){ -// sqlQueryBuilder.append(" and userId = %s".formatted(userId)); -// } -// -// return sqlQueryBuilder.toString(); -// } + @Select("select * from tempuser") List getAllUsers(); diff --git a/src/main/java/com/educare/unitylend/model/BorrowRequest.java b/src/main/java/com/educare/unitylend/model/BorrowRequest.java index 25bffb1..5f5d20d 100644 --- a/src/main/java/com/educare/unitylend/model/BorrowRequest.java +++ b/src/main/java/com/educare/unitylend/model/BorrowRequest.java @@ -30,7 +30,7 @@ public class BorrowRequest { private BigDecimal collectedAmount; @Getter private BigDecimal targetAmount; - public String getBorrowerid() { + public String getBorrowerId() { return borrower.getUserid(); } } diff --git a/src/main/java/com/educare/unitylend/model/Community.java b/src/main/java/com/educare/unitylend/model/Community.java index 022b45e..327798d 100644 --- a/src/main/java/com/educare/unitylend/model/Community.java +++ b/src/main/java/com/educare/unitylend/model/Community.java @@ -2,13 +2,14 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor public class Community { - private String communityid; + private String communityid; private String communityname; private String commontag; diff --git a/src/main/java/com/educare/unitylend/model/User.java b/src/main/java/com/educare/unitylend/model/User.java index b191a6b..3e96bd1 100644 --- a/src/main/java/com/educare/unitylend/model/User.java +++ b/src/main/java/com/educare/unitylend/model/User.java @@ -11,15 +11,15 @@ @NoArgsConstructor @AllArgsConstructor public class User { - private String userid; + private String userId; private String password; private String name; private String email; private LocalDate dob; private Integer income; private Integer borrowingLimit; - private String officename; - private String collegeuniversity; + private String officeName; + private String collegeUniversity; private String locality; private boolean isActive; @@ -36,15 +36,15 @@ public Integer getIncome() { } public String getOfficename() { - return officename; + return officeName; } public void setOfficename(String officename) { - this.officename = officename; + this.officeName = officename; } public String getCollegeuniversity() { - return collegeuniversity; + return collegeUniversity; } public String getPassword() { @@ -64,11 +64,11 @@ public LocalDate getDob() { } public void setCollegeuniversity(String collegeuniversity) { - this.collegeuniversity = collegeuniversity; + this.collegeUniversity = collegeuniversity; } public String getUserid() { - return userid; + return userId; } public void setPassword(String password) { @@ -88,7 +88,7 @@ public void setDob(LocalDate dob) { } public void setUserid(String userid) { - this.userid = userid; + this.userId = userid; } public String getLocality() { diff --git a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java index 2568bda..f435606 100644 --- a/src/main/java/com/educare/unitylend/service/BorrowRequestService.java +++ b/src/main/java/com/educare/unitylend/service/BorrowRequestService.java @@ -9,5 +9,7 @@ public interface BorrowRequestService { List getRequestedCommunitiesByUserId(String userId) throws ServiceException; - boolean raiseBorrowRequestForUserid(String userId, BorrowRequest borrowRequest) throws ServiceException; + boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException; + + void createBorrowRequest(BorrowRequest borrowRequest) 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 cc067bc..16ba291 100644 --- a/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java +++ b/src/main/java/com/educare/unitylend/service/impl/BorrowRequestServiceImpl.java @@ -21,11 +21,15 @@ public class BorrowRequestServiceImpl implements BorrowRequestService { private UserRepository userRepository; private BorrowRequestRepository borrowRequestRepository; public List getRequestedCommunitiesByUserId(String userId) throws ServiceException{ - List communities=borrowRequestRepository.getBorrowRequestesByUserInCommunities(userId); + List communities=borrowRequestRepository.getBorrowRequestByUserId(userId); System.out.println(communities); return communities; } - public boolean raiseBorrowRequestForUserid(String userId, BorrowRequest borrowRequest) throws ServiceException { + + public void createBorrowRequest(BorrowRequest borrowRequest) { + borrowRequestRepository.createBorrowRequest(borrowRequest); + } + public boolean raiseBorrowRequestByUserId(String userId, BorrowRequest borrowRequest) throws ServiceException { try { // Assuming returnPeriod is in days BigDecimal monthlyInterestRate = new BigDecimal("50.0").divide(new BigDecimal(12 * 100), 10, RoundingMode.HALF_UP);