diff --git a/src/main/java/org/example/Controller/TransactionController.java b/src/main/java/org/example/Controller/TransferCalculator.java similarity index 90% rename from src/main/java/org/example/Controller/TransactionController.java rename to src/main/java/org/example/Controller/TransferCalculator.java index f125682..91139f2 100644 --- a/src/main/java/org/example/Controller/TransactionController.java +++ b/src/main/java/org/example/Controller/TransferCalculator.java @@ -1,6 +1,6 @@ package org.example.Controller; -public class TransactionController{ +public class TransferCalculator { public int receiveMoneyTransaction( int receiverCustomerAmount, int transferAmount){ return receiverCustomerAmount + transferAmount; diff --git a/src/main/java/org/example/DBController.java b/src/main/java/org/example/DBController.java index 5b45174..a90cd1f 100644 --- a/src/main/java/org/example/DBController.java +++ b/src/main/java/org/example/DBController.java @@ -1,5 +1,6 @@ package org.example; import org.example.Model.Customer; +import org.example.Model.TransactionAudit; import java.sql.*; import java.sql.DriverManager; @@ -128,6 +129,144 @@ public boolean updateCustomerFunds(int customerId, int newAmount) { //void return false; } + public void createTransactionAudit(int senderId, String senderName, int moneyInCents, int getterId, String getterName) throws SQLException { + String sql = "INSERT INTO transactions_audit (sender_id, sender_nickname, amount_sent, receiver_id, receiver_nickname) VALUES (?, ?, ?, ?, ?)"; + + PreparedStatement preparedStatement = connection.prepareStatement( + sql, + Statement.RETURN_GENERATED_KEYS + ); + { + + ps.setInt(1, senderId); + ps.setString(2, senderName); + ps.setInt(3, moneyInCents); + ps.setInt(4, getterId); + ps.setString(5, getterName); + + int rows = ps.executeUpdate(); // returns 1 + System.out.println("Rows inserted: " + rows); + } + } + + public TransactionAudit returnTransactionAudit(int transactionid) throws SQLException { + + int id = transactionid; + int sender_id = 0; + String sender_nickname = null; + int amount_sent = 0; + int receiver_id = 0; + String receiver_nickname = null; + String time = null; + + String sql = "SELECT id, sender_id, sender_nickname, amount_sent, receiver_id, receiver_nickname FROM transactions_audit WHERE id = ?"; + // + customerId + " (id, nickname, money, password) " + "VALUES (?, ?, ?)"; + + try ( + PreparedStatement ps = connection.prepareStatement(sql)) { + ps.setLong(1, id); + + try (ResultSet rs = ps.executeQuery()) { + + while (rs.next()) { + id = rs.getInt("id"); + sender_id = rs.getInt("sender_id"); + sender_nickname = rs.getString("sender_nickname"); + amount_sent = rs.getInt("amount_sent"); + receiver_id = rs.getInt("receiver_id"); + receiver_nickname = rs.getString("receiver_nickname"); + time = rs.getString("time"); + } + } + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + return new TransactionAudit(id, sender_id, sender_nickname, amount_sent, receiver_id, receiver_nickname, time); + } + + public void insertIntoFriendships(int senderId, int receiverId) throws SQLException { + String sql = "INSERT INTO friendships (customer_id, friend_id) VALUES (?, ?)"; + + PreparedStatement ps = connection.prepareStatement(sql); + ps.setLong(1, senderId); // customer_id + ps.setLong(2, receiverId); // friend_id + ps.executeUpdate(); + } + + public boolean checkIfHasFriend(int senderId, int receiverId) throws SQLException { + String sql = "SELECT FROM friendships WHERE customer_id = ? AND friend_id = ?"; + PreparedStatement ps = connection.prepareStatement(sql); + + ps.setLong(1, senderId); + ps.setLong(2, receiverId); + + ResultSet rs = ps.executeQuery(); + boolean result = rs.next(); + + if (!result) { + ps.setLong(1, receiverId); + ps.setLong(2, senderId); + + rs = ps.executeQuery(); + return rs.next(); + } + return true; + } + + public void insertIntoTransfers(int senderId, int receiverId, int amount) throws SQLException { + + PreparedStatement addTx = connection.prepareStatement("INSERT INTO transfers (sender_id, receiver_id, amount_cents) VALUES (?,?,?)"); + addTx.setLong(1, senderId); + addTx.setLong(2, receiverId); + addTx.setLong(3, amount); + addTx.executeUpdate(); + } + + public void insertIntoTransferTotals1(int senderId, int receiverId, int amount) throws SQLException { + PreparedStatement upsert1 = connection.prepareStatement( + """ + INSERT INTO transfer_totals (customer_id, friend_id, sent_cents) + VALUES (?, ?, ?) + ON CONFLICT (customer_id, friend_id) + DO UPDATE SET sent_cents = transfer_totals.sent_cents + EXCLUDED.sent_cents + """); + upsert1.setLong(1, senderId); + upsert1.setLong(2, receiverId); + upsert1.setLong(3, amount); + upsert1.executeUpdate(); + } + + public void insertIntoTransferTotals2(int senderId, int receiverId, int amount) throws SQLException { + PreparedStatement upsert2 = connection.prepareStatement( + """ + INSERT INTO transfer_totals (customer_id, friend_id, received_cents) + VALUES (?, ?, ?) + ON CONFLICT (customer_id, friend_id) + DO UPDATE SET received_cents = transfer_totals.received_cents + EXCLUDED.received_cents + """); + upsert2.setLong(1, receiverId); + upsert2.setLong(2, senderId); + upsert2.setLong(3, amount); + upsert2.executeUpdate(); + } + + public void createTable() throws SQLException { + String sql = """ + CREATE TABLE IF NOT EXISTS test ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + friend_name TEXT NOT NULL, + friend_status TEXT NOT NULL, + total_money_sent BIGINT NOT NULL, + total_money_received BIGINT NOT NULL, + since_when TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP + ); + """; + + Statement st = connection.createStatement(); + st.executeUpdate(sql); + + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index e532436..c03bc6f 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,17 +1,29 @@ package org.example; import org.example.Model.Customer; +import org.example.Model.TransactionAudit; +import org.example.Services.CustomerServices; +import org.example.Services.ThreadTest; +import org.example.Services.TransferHandler; +import java.io.IOException; import java.sql.*; public class Main { - public static void main(String[] args) throws ClassNotFoundException, SQLException { + public static void main(String[] args) throws SQLException, IOException { +// DBController dbcontrol = new DBController(); +// +// ThreadTest R1 = new ThreadTest( "Thread-1"); +// R1.start(); +// +// ThreadTest R2 = new ThreadTest( "Thread-2"); +// R2.start(); + CustomerServices cservices = new CustomerServices(); - //drivermanager.addCustomerRecord(name, money, password); - + cservices.makeTransfer("derry", "jennifer", 2000); } } diff --git a/src/main/java/org/example/Model/Customer.java b/src/main/java/org/example/Model/Customer.java index b6c4885..b9cd46b 100644 --- a/src/main/java/org/example/Model/Customer.java +++ b/src/main/java/org/example/Model/Customer.java @@ -6,8 +6,8 @@ public class Customer{ private String user; private int moneyInCents; private String password; - private String realName; - private String email; + private String realName; + private String email; public Customer(int i, String ss, int i1, String password) { this.Id = i; diff --git a/src/main/java/org/example/Model/TransactionAudit.java b/src/main/java/org/example/Model/TransactionAudit.java new file mode 100644 index 0000000..9d45637 --- /dev/null +++ b/src/main/java/org/example/Model/TransactionAudit.java @@ -0,0 +1,8 @@ +package org.example.Model; + +public record TransactionAudit(int id, int senderId, String senderName, int moneyInCents, int getterId, String getterName, String time) { + + +} + +// money in cents \ No newline at end of file diff --git a/src/main/java/org/example/Model/TransactionRecords.java b/src/main/java/org/example/Model/TransactionRecords.java deleted file mode 100644 index 04cb5af..0000000 --- a/src/main/java/org/example/Model/TransactionRecords.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.example.Model; - -public record TransactionRecords(int SenderId, int GetterId, int moneyInCents) { - - -} - -// money in cents \ No newline at end of file diff --git a/src/main/java/org/example/Other/DataAutomation.java b/src/main/java/org/example/Other/DataAutomation.java new file mode 100644 index 0000000..cc2ce45 --- /dev/null +++ b/src/main/java/org/example/Other/DataAutomation.java @@ -0,0 +1,6 @@ +package org.example.Other; + +public class DataAutomation { + + +} diff --git a/src/main/java/org/example/Other/nicknames.csv b/src/main/java/org/example/Other/nicknames.csv new file mode 100644 index 0000000..08a1e93 --- /dev/null +++ b/src/main/java/org/example/Other/nicknames.csv @@ -0,0 +1,121 @@ + Valentino + Keshawn + Gunner + Jenny + Adonis + Andre + Eddie + Heidi + Rebecca + John + Philip + Kadin + Saige Fuentes. + Bowen Higgins. + Leighton Kramer. + Kylan Gentry. + Amelie Griffith. + Franklin Sierra. + Marceline Avila. + Jaylen Blackwell. + + Kaisley Webster + Shawn Wilson + Luna Farley + Graysen Bradley + Vanessa Nixon + Cory Valencia + Maddison Lawson + Lane Harrell + Kara Velez + Kareem Robinson + Nora Bradley + Richard Patrick + Lyra Hurst + Neil Lee + Scarlett Reid + Josue McCall + Kai Martin + Mateo Velazquez + Jaliyah Curtis + Muhammad Parker + Aubrey Castillo + Kai Weeks + Karen Sloan + Ocean Allison + Chelsea Gallagher + Marcos Palacios + Bria Rojas + Colin Tucker + Esther Peterson + Santiago Payne + London Bass + Landen Shannon + Harlee Rubio + Titan Peck + Crystal Potter + Lucca Schneider + Delaney Martin + Mateo Portillo + Nathalie Richards + Holden Weiss + Lennox Vaughan + Castiel Patton + Lorelei Lim + Cal Kirk + Ellis Jefferson + Raylan Avila + Amiyah Marshall + Kaiden Henson + Kinslee Lynch + Zane Silva + Lucia Quinn + Rhys Townsend + Azalea Cano + Terry Cook + Aaliyah Noble + Idris Higgins + Leighton Velez + Kareem Terrell + Paityn Villa + Clay Skinner + Mara Cisneros + Alden Leach + Martha Chase + Otis Frederick + Sariyah Zhang + Isaias Brewer + Thea Farrell + Ty Vo + Artemis Saunders + Kasen Moyer + Zola Walton + Dominick Novak + Kaiya May + Finley McLean + Sky Ali + Arjun Gilbert + Jocelyn Daniels + Xander Monroe + Carly Calhoun + Gary Horton + Aitana Hickman + Jakobe Snyder + Callie Humphrey + Krew Chandler + Viviana Saunders + Kasen Pace + Giana Crawford + Kevin Harper + Ana Rivera + Charles Zuniga + Leslie McDowell + Lachlan Quinn + Heaven Armstrong + Grant Bryant + Parker Price + Brooks Frazier + Octavia Walter + Lochlan Atkins + Mina Zavala + Dillon Petersen \ No newline at end of file diff --git a/src/main/java/org/example/Output_files/allcustomers.csv b/src/main/java/org/example/Output_files/allcustomers.csv deleted file mode 100644 index eb9d233..0000000 --- a/src/main/java/org/example/Output_files/allcustomers.csv +++ /dev/null @@ -1,13 +0,0 @@ -1 , diego , 8000 -2 , brad , 8000 -3 , popua , 20400 -4 , nigel , 7000 -5 , enrike , 12000 -6 , joshua , 2000 -7 , sasha , 700 -8 , lisa , 7050010 -9 , audrey , 2000 -10 , york , 4000 -11 , sughi , 4000 -12 , ryan , 0 -13 , dave , 1150 diff --git a/src/main/java/org/example/Output_files/customerTransactions/audrey.csv b/src/main/java/org/example/Output_files/customerTransactions/audrey.csv deleted file mode 100644 index a465ff6..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/audrey.csv +++ /dev/null @@ -1,2 +0,0 @@ -You have received: 1000, from enrike, | 2025.05.30 | 01.03.54 -You have received: 1000, from enrike, | 2025.05.30 | 01.25.13 diff --git a/src/main/java/org/example/Output_files/customerTransactions/brad.csv b/src/main/java/org/example/Output_files/customerTransactions/brad.csv deleted file mode 100644 index e340531..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/brad.csv +++ /dev/null @@ -1 +0,0 @@ -You have sent: 3000, to sasha, | 2025.05.30 | 01.02.42 diff --git a/src/main/java/org/example/Output_files/customerTransactions/dave.csv b/src/main/java/org/example/Output_files/customerTransactions/dave.csv deleted file mode 100644 index ef9223b..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/dave.csv +++ /dev/null @@ -1 +0,0 @@ -You have received: 1000, from enrike, | 2025.05.30 | 10.34.37 diff --git a/src/main/java/org/example/Output_files/customerTransactions/diego.csv b/src/main/java/org/example/Output_files/customerTransactions/diego.csv deleted file mode 100644 index dbe78b3..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/diego.csv +++ /dev/null @@ -1 +0,0 @@ -You have received: 3000, from sasha, | 2025.06.02 | 17.46.55 diff --git a/src/main/java/org/example/Output_files/customerTransactions/enrike.csv b/src/main/java/org/example/Output_files/customerTransactions/enrike.csv deleted file mode 100644 index fee80ba..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/enrike.csv +++ /dev/null @@ -1,3 +0,0 @@ -You have sent: 1000, to audrey, | 2025.05.30 | 01.03.54 -You have sent: 1000, to audrey, | 2025.05.30 | 01.25.13 -You have sent: 1000, to dave, | 2025.05.30 | 10.34.37 diff --git a/src/main/java/org/example/Output_files/customerTransactions/sasha.csv b/src/main/java/org/example/Output_files/customerTransactions/sasha.csv deleted file mode 100644 index 68d019a..0000000 --- a/src/main/java/org/example/Output_files/customerTransactions/sasha.csv +++ /dev/null @@ -1,2 +0,0 @@ -You have received: 3000, from brad, | 2025.05.30 | 01.02.42 -You have sent: 3000, to diego, | 2025.06.02 | 17.46.55 diff --git a/src/main/java/org/example/Output_files/customernumber_id.csv b/src/main/java/org/example/Output_files/customernumber_id.csv deleted file mode 100644 index ca7bf83..0000000 --- a/src/main/java/org/example/Output_files/customernumber_id.csv +++ /dev/null @@ -1 +0,0 @@ -13 \ No newline at end of file diff --git a/src/main/java/org/example/Output_files/friends/brad friends.csv b/src/main/java/org/example/Output_files/friends/brad friends.csv deleted file mode 100644 index fb7ec53..0000000 --- a/src/main/java/org/example/Output_files/friends/brad friends.csv +++ /dev/null @@ -1 +0,0 @@ -sasha \ No newline at end of file diff --git a/src/main/java/org/example/Output_files/friends/sasha friends.csv b/src/main/java/org/example/Output_files/friends/sasha friends.csv deleted file mode 100644 index 1571b64..0000000 --- a/src/main/java/org/example/Output_files/friends/sasha friends.csv +++ /dev/null @@ -1 +0,0 @@ -brad \ No newline at end of file diff --git a/src/main/java/org/example/Output_files/messages/brad messages.csv b/src/main/java/org/example/Output_files/messages/brad messages.csv deleted file mode 100644 index 67cdc3b..0000000 --- a/src/main/java/org/example/Output_files/messages/brad messages.csv +++ /dev/null @@ -1,2 +0,0 @@ -You received a friend request from - sasha , at 2025.05.30 | 09.28.13 -You received a friend request from - sasha , at 2025.05.30 | 09.31.47 diff --git a/src/main/java/org/example/Output_files/messages/sasha messages.csv b/src/main/java/org/example/Output_files/messages/sasha messages.csv deleted file mode 100644 index 31f4e79..0000000 --- a/src/main/java/org/example/Output_files/messages/sasha messages.csv +++ /dev/null @@ -1,2 +0,0 @@ -brad accepted your friend request! from - brad , at 2025.05.30 | 09.28.14 -brad accepted your friend request! from - brad , at 2025.05.30 | 09.31.54 diff --git a/src/main/java/org/example/Output_files/transactionsHistory/transactionsHistory.csv b/src/main/java/org/example/Output_files/transactionsHistory/transactionsHistory.csv deleted file mode 100644 index 76eec4a..0000000 --- a/src/main/java/org/example/Output_files/transactionsHistory/transactionsHistory.csv +++ /dev/null @@ -1,5 +0,0 @@ -Sender ID: 2, name: brad | Receiver ID: 7, name: sasha | Amount sent: 3000 | 2025.05.30 | 01.02.42 -Sender ID: 5, name: enrike | Receiver ID: 9, name: audrey | Amount sent: 1000 | 2025.05.30 | 01.03.54 -Sender ID: 5, name: enrike | Receiver ID: 9, name: audrey | Amount sent: 1000 | 2025.05.30 | 01.25.13 -Sender ID: 5, name: enrike | Receiver ID: 13, name: dave | Amount sent: 1000 | 2025.05.30 | 10.34.37 -Sender ID: 7, name: sasha , Receiver ID: 1, name: diego , Amount sent: 3000 , 2025.06.02 | 17.46.55 diff --git a/src/main/java/org/example/Controller/CustomerServices.java b/src/main/java/org/example/Services/CustomerServices.java similarity index 57% rename from src/main/java/org/example/Controller/CustomerServices.java rename to src/main/java/org/example/Services/CustomerServices.java index b53cf75..60d146f 100644 --- a/src/main/java/org/example/Controller/CustomerServices.java +++ b/src/main/java/org/example/Services/CustomerServices.java @@ -1,5 +1,6 @@ -package org.example.Controller; +package org.example.Services; +import org.example.Controller.TransferCalculator; import org.example.DBController; import org.example.Model.Customer; @@ -10,7 +11,7 @@ public class CustomerServices { DBController dbcontroller = new DBController(); - TransactionController transactions = new TransactionController(); + TransferCalculator transactions = new TransferCalculator(); public CustomerServices() throws SQLException { } @@ -27,27 +28,54 @@ public void depositMoney(String customerName, int depositAmount) throws IOExcept } } + public void makeTransfer(String nameSenderCustomer, String nameReceiverCustomer, int amountToSend) throws SQLException, IOException { + int senderreturnedId = dbcontroller.findCustomerByUsername(nameSenderCustomer); + int receiverreturnedId = dbcontroller.findCustomerByUsername(nameReceiverCustomer); - public boolean sendMoneyToSomeone(String nameSenderCustomer, String nameReceiverCustomer, int amountToSend) throws IOException, SQLException { + boolean sendmoney = sendMoneyToSomeone(senderreturnedId, amountToSend); + if (sendmoney){ + receiveMoney(receiverreturnedId, amountToSend); + updateDbAfterTransfer(senderreturnedId, nameSenderCustomer, receiverreturnedId, nameReceiverCustomer, amountToSend); + System.out.println("Transfer is done"); + } + } + + // what if funds insufficient? add error handlers + public boolean sendMoneyToSomeone(int senderreturnedId, int amountToSend) throws IOException, SQLException { - int senderreturnedId = dbcontroller.findCustomerByUsername(nameSenderCustomer); Customer sendercustomer = dbcontroller.returnRecord(senderreturnedId); - int receiverreturnedId = dbcontroller.findCustomerByUsername(nameReceiverCustomer); - Customer receivercustomer = dbcontroller.returnRecord(receiverreturnedId); int senderMoney = sendercustomer.getMoneyInCents(); - int receiverMoney = receivercustomer.getMoneyInCents(); boolean hasenough = transactions.checkIfCustomerHasFundsToMakeTransaction(senderMoney, amountToSend); if (hasenough) { int newsenderamount = transactions.sendMoneyTransaction(senderMoney, amountToSend); - int newreceiveramount = transactions.receiveMoneyTransaction(receiverMoney, amountToSend); dbcontroller.updateCustomerFunds(senderreturnedId, newsenderamount); - dbcontroller.updateCustomerFunds(receiverreturnedId, newreceiveramount); return true; } return false; + } // add isMoneyReceived method, splitting responsibilities and securing the transfers + + public void receiveMoney(int receiverreturnedId, int amountToSend) throws SQLException { + + Customer receivercustomer = dbcontroller.returnRecord(receiverreturnedId); + int receiverMoney = receivercustomer.getMoneyInCents(); + int newreceiveramount = transactions.receiveMoneyTransaction(receiverMoney, amountToSend); + + dbcontroller.updateCustomerFunds(receiverreturnedId, newreceiveramount); + } + public void updateDbAfterTransfer(int senderreturnedId, String nameSenderCustomer, int receiverreturnedId, String nameReceiverCustomer, int amountToSend) throws SQLException { + + dbcontroller.insertIntoTransferTotals1(senderreturnedId, receiverreturnedId, amountToSend); + dbcontroller.insertIntoTransferTotals2(senderreturnedId, receiverreturnedId, amountToSend); + dbcontroller.createTransactionAudit(senderreturnedId, nameSenderCustomer, amountToSend, receiverreturnedId, nameReceiverCustomer); + + boolean isfriends = dbcontroller.checkIfHasFriend(senderreturnedId, receiverreturnedId); + if (isfriends){ + dbcontroller.insertIntoTransfers(senderreturnedId, receiverreturnedId, amountToSend); + } + } /* private void insufficientFundsMessage() { System.out.println("You don't have the amount selected to continue with this transaction!"); diff --git a/src/main/java/org/example/Services/ThreadTest.java b/src/main/java/org/example/Services/ThreadTest.java new file mode 100644 index 0000000..7f377e2 --- /dev/null +++ b/src/main/java/org/example/Services/ThreadTest.java @@ -0,0 +1,34 @@ +package org.example.Services; + +public class ThreadTest implements Runnable { + + private Thread t; + private String threadName; + + public ThreadTest(String name) { + threadName = name; + System.out.println("Creating " + threadName ); + } + + public void run() { + System.out.println("Running " + threadName ); + try { + for(int i = 4; i > 0; i--) { + System.out.println("Thread: " + threadName + ", " + i); + // Let the thread sleep for a while. + Thread.sleep(50); + } + } catch (InterruptedException e) { + System.out.println("Thread " + threadName + " interrupted."); + } + System.out.println("Thread " + threadName + " exiting."); + } + + public void start () { + System.out.println("Starting " + threadName ); + if (t == null) { + t = new Thread (this, threadName); + t.start (); + } + } +} diff --git a/src/main/java/org/example/Services/TransferHandler.java b/src/main/java/org/example/Services/TransferHandler.java new file mode 100644 index 0000000..6113ab5 --- /dev/null +++ b/src/main/java/org/example/Services/TransferHandler.java @@ -0,0 +1,24 @@ +package org.example.Services; + +import org.example.DBController; + +import java.io.IOException; +import java.sql.SQLException; + +public class TransferHandler { + // CAN BE AN OBJECT RECEIVED FROM THE FRONTEND + + DBController dbcontroller; + CustomerServices customerservices = new CustomerServices(); + + String nameSenderCustomer = null; + String nameReceiverCustomer = null; + int amountToSend = 0; + + public TransferHandler(String nameSenderCustomer, String nameReceiverCustomer, int amountToSend) throws SQLException, IOException { + this.nameSenderCustomer = nameSenderCustomer; + this.nameReceiverCustomer = nameReceiverCustomer; + this.amountToSend = amountToSend; + } + +} diff --git a/src/test/java/org/example/Controller/CustomerServicesTest.java b/src/test/java/org/example/Controller/CustomerServicesTest.java index bd7b61f..7f73552 100644 --- a/src/test/java/org/example/Controller/CustomerServicesTest.java +++ b/src/test/java/org/example/Controller/CustomerServicesTest.java @@ -1,5 +1,6 @@ package org.example.Controller; +import org.example.Services.CustomerServices; import org.junit.Test; import java.io.IOException; @@ -29,7 +30,6 @@ public void depositMoneyTest () throws IOException, SQLException { @Test public void sendMoneyToSomeoneTest() throws SQLException, IOException { - customerActionsController.sendMoneyToSomeone("jennifer", "derry", 8000); // what if transaction breaks for some reason? or if he doesn't receive money? or if she sends money, // but he doesn't receive? } diff --git a/src/test/java/org/example/Controller/DBControllerTest.java b/src/test/java/org/example/Controller/DBControllerTest.java index ffc5813..a0a8439 100644 --- a/src/test/java/org/example/Controller/DBControllerTest.java +++ b/src/test/java/org/example/Controller/DBControllerTest.java @@ -2,6 +2,7 @@ import org.example.DBController; import org.example.Model.Customer; +import org.example.Model.TransactionAudit; import org.junit.Test; import static org.junit.Assert.fail; @@ -67,4 +68,19 @@ public void findCustomerByUsernameTest() { } + @Test + public void insertIntoFriendshipsTest() throws SQLException { + int senderId = 5; + int receiverId = 3; + + dbcontroller.insertIntoFriendships(senderId, receiverId); + } + + @Test + public void checkIfHasFriendTest() throws SQLException { + boolean isfriend = dbcontroller.checkIfHasFriend(7, 5); + // fix this, now it is only one way check + assertThat(isfriend).isTrue(); + } + } diff --git a/src/test/java/org/example/Controller/TransactionControllerTest.java b/src/test/java/org/example/Controller/TransactionControllerTest.java deleted file mode 100644 index 4cc9b7b..0000000 --- a/src/test/java/org/example/Controller/TransactionControllerTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.example.Controller; - -import org.example.Model.Customer; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.fail; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class TransactionControllerTest { - // I guess this class should implement the main logic - // UserModel expectedUser = new UserModel(55, "bb", 100); - -} diff --git a/src/test/java/org/example/Controller/TransferCalculatorTest.java b/src/test/java/org/example/Controller/TransferCalculatorTest.java new file mode 100644 index 0000000..522d08d --- /dev/null +++ b/src/test/java/org/example/Controller/TransferCalculatorTest.java @@ -0,0 +1,37 @@ +package org.example.Controller; + +import org.example.DBController; +import org.example.Model.Customer; +import org.example.Model.TransactionAudit; +import org.junit.Before; +import org.junit.Test; + +import java.sql.SQLException; + +import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TransferCalculatorTest { + // I guess this class should implement the main logic + // UserModel expectedUser = new UserModel(55, "bb", 100); + + @Test + public void returnAuditRecordTest() throws SQLException { + DBController dbcontroller = new DBController(); + + TransactionAudit returnedAudit = dbcontroller.returnTransactionAudit(1); + + int senderid = returnedAudit.senderId(); + String sendername = returnedAudit.senderName(); + int amount = returnedAudit.moneyInCents(); + int getterid = returnedAudit.getterId(); + String gettername = returnedAudit.getterName(); + String time = returnedAudit.time(); + + System.out.println(senderid + " , " + sendername + " , " + amount + " , " + getterid + " , " + gettername + " , " + time); + //drivermanager.addCustomerRecord(name, money, password); + +} +} diff --git a/target/classes/org/example/Controller/CustomerServices.class b/target/classes/org/example/Controller/CustomerServices.class deleted file mode 100644 index f5b766c..0000000 Binary files a/target/classes/org/example/Controller/CustomerServices.class and /dev/null differ diff --git a/target/classes/org/example/Controller/TransactionController.class b/target/classes/org/example/Controller/TransactionController.class deleted file mode 100644 index 3272022..0000000 Binary files a/target/classes/org/example/Controller/TransactionController.class and /dev/null differ diff --git a/target/classes/org/example/Controller/TransferCalculator.class b/target/classes/org/example/Controller/TransferCalculator.class new file mode 100644 index 0000000..e926d0c Binary files /dev/null and b/target/classes/org/example/Controller/TransferCalculator.class differ diff --git a/target/classes/org/example/DBController.class b/target/classes/org/example/DBController.class index f0308ba..70e9436 100644 Binary files a/target/classes/org/example/DBController.class and b/target/classes/org/example/DBController.class differ diff --git a/target/classes/org/example/Main.class b/target/classes/org/example/Main.class index 252fbb3..612a0f0 100644 Binary files a/target/classes/org/example/Main.class and b/target/classes/org/example/Main.class differ diff --git a/target/classes/org/example/Model/TransactionAudit.class b/target/classes/org/example/Model/TransactionAudit.class new file mode 100644 index 0000000..0b83a6f Binary files /dev/null and b/target/classes/org/example/Model/TransactionAudit.class differ diff --git a/target/classes/org/example/Model/TransactionRecords.class b/target/classes/org/example/Model/TransactionRecords.class deleted file mode 100644 index b22fbb4..0000000 Binary files a/target/classes/org/example/Model/TransactionRecords.class and /dev/null differ diff --git a/target/classes/org/example/Other/DataAutomation.class b/target/classes/org/example/Other/DataAutomation.class new file mode 100644 index 0000000..8c018be Binary files /dev/null and b/target/classes/org/example/Other/DataAutomation.class differ diff --git a/target/classes/org/example/Services/CustomerServices.class b/target/classes/org/example/Services/CustomerServices.class new file mode 100644 index 0000000..1914a07 Binary files /dev/null and b/target/classes/org/example/Services/CustomerServices.class differ diff --git a/target/classes/org/example/Services/ThreadTest.class b/target/classes/org/example/Services/ThreadTest.class new file mode 100644 index 0000000..234db83 Binary files /dev/null and b/target/classes/org/example/Services/ThreadTest.class differ diff --git a/target/classes/org/example/Services/TransferHandler.class b/target/classes/org/example/Services/TransferHandler.class new file mode 100644 index 0000000..1e4a94a Binary files /dev/null and b/target/classes/org/example/Services/TransferHandler.class differ diff --git a/target/test-classes/org/example/Controller/CustomerServicesTest.class b/target/test-classes/org/example/Controller/CustomerServicesTest.class index 2d784ae..22e4a58 100644 Binary files a/target/test-classes/org/example/Controller/CustomerServicesTest.class and b/target/test-classes/org/example/Controller/CustomerServicesTest.class differ diff --git a/target/test-classes/org/example/Controller/DBControllerTest.class b/target/test-classes/org/example/Controller/DBControllerTest.class index 75e97ff..ae2a0fa 100644 Binary files a/target/test-classes/org/example/Controller/DBControllerTest.class and b/target/test-classes/org/example/Controller/DBControllerTest.class differ diff --git a/target/test-classes/org/example/Controller/TransactionControllerTest.class b/target/test-classes/org/example/Controller/TransactionControllerTest.class index d8be970..d22a383 100644 Binary files a/target/test-classes/org/example/Controller/TransactionControllerTest.class and b/target/test-classes/org/example/Controller/TransactionControllerTest.class differ