diff --git a/.gitignore b/.gitignore index 24d6437..b72b8d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ +# Default ignored files +/shelf/ +/workspace.xml /target/ +logback.xml +logs/ +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 8ac1a0a..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -target/ \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index cab9f4a..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index a156f52..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index a468a99..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9881e8d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 9661ac7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/logs/app.log b/logs/app.log deleted file mode 100644 index e6b2510..0000000 --- a/logs/app.log +++ /dev/null @@ -1,29 +0,0 @@ -2025-07-01 12:41:45.151 INFO [pool-1-thread-1] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 12:41:45.151 INFO [pool-1-thread-2] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 12:41:45.174 INFO [pool-1-thread-1] org.example.Main - User johnny logged in -2025-07-01 14:58:19.696 ERROR [pool-1-thread-1] o.example.Services.CustomerServices - the money weren't received, it returned false -2025-07-01 14:58:19.698 INFO [pool-1-thread-1] org.example.Main - User johnny sent the money -2025-07-01 14:58:19.733 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were sent -2025-07-01 14:58:19.733 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were received -2025-07-01 14:58:19.762 INFO [pool-1-thread-2] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 14:58:19.775 INFO [pool-1-thread-2] org.example.Main - User johnny sent the money -2025-07-01 15:02:53.411 ERROR [pool-1-thread-1] o.example.Services.CustomerServices - the money weren't received, it returned false -2025-07-01 15:02:53.449 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were sent -2025-07-01 15:02:53.451 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were received -2025-07-01 15:02:53.467 INFO [pool-1-thread-2] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 15:04:32.451 ERROR [pool-1-thread-2] o.example.Services.CustomerServices - the money weren't received, it returned false -2025-07-01 15:04:32.475 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money were sent -2025-07-01 15:04:32.477 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money were received -2025-07-01 15:04:32.507 INFO [pool-1-thread-1] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 15:26:37.111 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money were sent -2025-07-01 15:26:37.110 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were sent -2025-07-01 15:26:37.115 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money were received -2025-07-01 15:26:37.115 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money were received -2025-07-01 15:26:37.144 INFO [pool-1-thread-2] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 15:26:37.144 INFO [pool-1-thread-1] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 15:29:53.132 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money was sent -2025-07-01 15:29:53.132 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money was sent -2025-07-01 15:29:53.137 INFO [pool-1-thread-1] o.example.Services.CustomerServices - money was received -2025-07-01 15:29:53.137 INFO [pool-1-thread-2] o.example.Services.CustomerServices - money was received -2025-07-01 15:29:53.156 INFO [pool-1-thread-2] org.example.DBRepository - Number of rows inserted: 1 -2025-07-01 15:29:53.156 INFO [pool-1-thread-1] org.example.DBRepository - Number of rows inserted: 1 diff --git a/pom.xml b/pom.xml index ad9ab46..82e5c2f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,9 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + + org.springframework.boot + spring-boot-starter-parent + 3.3.0 + + org.example - AppForTests + AppwithPostgreSQL 1.0-SNAPSHOT @@ -14,6 +19,15 @@ UTF-8 + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + org.junit.jupiter junit-jupiter-api @@ -64,6 +78,11 @@ logback-classic 1.5.18 + + org.springframework.boot + spring-boot-autoconfigure + 3.4.4 + @@ -79,6 +98,33 @@ + + org.flywaydb + flyway-maven-plugin + 11.10.0 + + flyway-db + jdbc:postgresql://172.31.224.1:5432/findb + + + filesystem:src/main/resources/db/migration + + + + + + org.flywaydb + flyway-database-postgresql + 11.10.0 + + + + org.postgresql + postgresql + 42.7.4 + + + \ No newline at end of file diff --git a/src/main/java/org/example/Currencies/CurrencyAPI.java b/src/main/java/org/example/Currencies/CurrencyAPI.java index 1bafc5a..87e870c 100644 --- a/src/main/java/org/example/Currencies/CurrencyAPI.java +++ b/src/main/java/org/example/Currencies/CurrencyAPI.java @@ -14,7 +14,7 @@ public class CurrencyAPI { - private static final String url_str = "https://v6.exchangerate-api.com/v6/79f34354ceb4dc1276fecca5/latest/USD"; + private static final String url_str = System.getenv("currencyAPI"); public HashMap getCurrencies() throws IOException { diff --git a/src/main/java/org/example/DriverManagerDB.java b/src/main/java/org/example/DriverManagerDB.java index 118da6d..c48e1d7 100644 --- a/src/main/java/org/example/DriverManagerDB.java +++ b/src/main/java/org/example/DriverManagerDB.java @@ -6,9 +6,9 @@ public class DriverManagerDB { - private final String url = "jdbc:postgresql://localhost:5432/findb"; // put into properties file - private final String username = "simon"; - private final String password = "password"; + private final String url = System.getenv("DBurl"); // put into properties file + private final String username = System.getenv("DBuser"); + private final String password = System.getenv("DBpassword"); public DriverManagerDB() throws SQLException { } diff --git a/src/main/java/org/example/Repositories/CustomerEntityRepository.java b/src/main/java/org/example/Repositories/CustomerEntityRepository.java new file mode 100644 index 0000000..ecb7ece --- /dev/null +++ b/src/main/java/org/example/Repositories/CustomerEntityRepository.java @@ -0,0 +1,132 @@ +package org.example.Repositories; + + +import org.example.DriverManagerDB; +import org.example.Model.Customer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.*; + +public class CustomerEntityRepository { + + DriverManagerDB drivermanagerdb = new DriverManagerDB(); + + Connection connection = drivermanagerdb.connect(); + + final Logger logger = LoggerFactory.getLogger(TransfersRepository.class); + + public CustomerEntityRepository() throws SQLException { + } + + public void addCustomerRecord(String name, int money, String password) throws SQLException { + String sql = "INSERT INTO customers (nickname, money, password) VALUES (?, ?, ?)"; + + PreparedStatement ps = connection.prepareStatement( + sql, + Statement.RETURN_GENERATED_KEYS);{ + + ps.setString(1, name); + ps.setInt(2, money); + ps.setString(3, password); + + int rows = ps.executeUpdate(); // returns 1 + logger.trace("Number of rows inserted: {}", rows); + if (rows == 0){ + logger.error("Error"); + } + try (ResultSet keys = ps.getGeneratedKeys()) { + if (keys.next()) { + long id = keys.getLong(1); // ← your SERIAL / IDENTITY value + logger.info("New customer id = {}", id); + } + } + } + } + + public Customer returnRecord(int customerId) throws SQLException { + + int id = customerId; + String name = null; + int money = 0; + String cusPassword = null; + String sql = "SELECT id, nickname, money, password FROM customers WHERE id = ?"; + + try ( + PreparedStatement ps = connection.prepareStatement(sql)) { + ps.setLong(1, id); + + ResultSet rs = ps.executeQuery(); + + while (rs.next()) { + id = rs.getInt("id"); // error here probably + name = rs.getString("nickname"); + money = rs.getInt("money"); + cusPassword = rs.getString("password"); + } + //TODO: make this code with error logging + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + return new Customer(id, name, money, cusPassword); + } + + public int findCustomerByUsername(String name){ + int id = 0; + String sql = "SELECT id FROM customers WHERE nickname = ?"; + try ( + PreparedStatement ps = connection.prepareStatement(sql)) { + ps.setString(1, name); + + ResultSet rs = ps.executeQuery(); + + while (rs.next()) { + id = rs.getInt("id"); + return id; + } + } catch (SQLException e) { + logger.error("error: {}", e); + } + return id; + } + + + public boolean updateCustomerFunds(int customerId, int newAmount) { //void + + String sql = "UPDATE customers SET money = ? WHERE id = ? "; + try ( // + PreparedStatement ps = connection.prepareStatement(sql)) { + + ps.setInt(1, newAmount); + ps.setInt(2,customerId); + + ps.executeUpdate(); + + } catch (SQLException e) { + System.out.println(e.getMessage()); + return false; + } + return true; + } + + 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; + } +} + diff --git a/src/main/java/org/example/DBRepository.java b/src/main/java/org/example/Repositories/TransfersRepository.java similarity index 58% rename from src/main/java/org/example/DBRepository.java rename to src/main/java/org/example/Repositories/TransfersRepository.java index e2dd101..9c972e4 100644 --- a/src/main/java/org/example/DBRepository.java +++ b/src/main/java/org/example/Repositories/TransfersRepository.java @@ -1,21 +1,21 @@ -package org.example; -import org.example.Model.Customer; +package org.example.Repositories; +import org.example.DriverManagerDB; import org.example.Model.TransactionAudit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.*; -public class DBRepository { +public class TransfersRepository { DriverManagerDB drivermanagerdb = new DriverManagerDB(); Connection connection = drivermanagerdb.connect(); - final Logger logger = LoggerFactory.getLogger(DBRepository.class); + final Logger logger = LoggerFactory.getLogger(TransfersRepository.class); - public DBRepository() throws SQLException { + public TransfersRepository() throws SQLException { } /* @@ -37,98 +37,6 @@ public void connectToDb(){ } */ - public void addCustomerRecord(String name, int money, String password) throws SQLException { - String sql = "INSERT INTO customers (nickname, money, password) VALUES (?, ?, ?)"; - - PreparedStatement ps = connection.prepareStatement( - sql, - Statement.RETURN_GENERATED_KEYS);{ - - ps.setString(1, name); - ps.setInt(2, money); - ps.setString(3, password); - - int rows = ps.executeUpdate(); // returns 1 - logger.trace("Number of rows inserted: {}", rows); - if (rows == 0){ - logger.error("Error"); - } - try (ResultSet keys = ps.getGeneratedKeys()) { - if (keys.next()) { - long id = keys.getLong(1); // ← your SERIAL / IDENTITY value - logger.info("New customer id = {}", id); - } - } - } - } - - public Customer returnRecord(int customerId) throws SQLException { - - int id = customerId; - String name = null; - int money = 0; - String cusPassword = null; - String sql = "SELECT id, nickname, money, password FROM customers WHERE id = ?"; - - try ( - PreparedStatement ps = connection.prepareStatement(sql)) { - ps.setLong(1, id); - - ResultSet rs = ps.executeQuery(); - - while (rs.next()) { - id = rs.getInt("id"); // error here probably - name = rs.getString("nickname"); - money = rs.getInt("money"); - cusPassword = rs.getString("password"); - } - //TODO: make this code with error logging - } catch (SQLException e) { - System.out.println(e.getMessage()); - } - return new Customer(id, name, money, cusPassword); - } - -// TODO: don't loop try catch in try catch - public int findCustomerByUsername(String name){ - int id = 0; - String sql = "SELECT id FROM customers WHERE nickname = ?"; - try ( - PreparedStatement ps = connection.prepareStatement(sql)) { - ps.setString(1, name); - - ResultSet rs = ps.executeQuery(); - - while (rs.next()) { - id = rs.getInt("id"); - return id; - } -//TODO: same problem, try without catch was looped in try catch - } catch (SQLException e) { - logger.error("error: {}", e); - } - return id; - } - - - public boolean updateCustomerFunds(int customerId, int newAmount) { //void - - String sql = "UPDATE customers SET money = ? WHERE id = ? "; - try ( // - PreparedStatement ps = connection.prepareStatement(sql)) { - - ps.setInt(1, newAmount); - ps.setInt(2,customerId); - - ps.executeUpdate(); - - } catch (SQLException e) { - System.out.println(e.getMessage()); - return false; - } - return true; - } - 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 (?, ?, ?, ?, ?)"; @@ -194,26 +102,6 @@ public void insertIntoFriendships(int senderId, int receiverId) throws SQLExcept 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 (?,?,?)"); diff --git a/src/main/java/org/example/Services/CustomerServices.java b/src/main/java/org/example/Services/CustomerServices.java index 6a4d9a4..b6a41ab 100644 --- a/src/main/java/org/example/Services/CustomerServices.java +++ b/src/main/java/org/example/Services/CustomerServices.java @@ -2,7 +2,8 @@ import org.example.Controller.TransferCalculator; import org.example.Currencies.CurrencyAPI; -import org.example.DBRepository; +import org.example.Repositories.CustomerEntityRepository; +import org.example.Repositories.TransfersRepository; import org.example.Model.Customer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,8 +15,8 @@ public class CustomerServices { - DBRepository dbrepository = new DBRepository(); - + TransfersRepository dbrepository = new TransfersRepository(); + CustomerEntityRepository customerentityrepository = new CustomerEntityRepository(); TransferCalculator transactions = new TransferCalculator(); final Logger logger = LoggerFactory.getLogger(CustomerServices.class); @@ -24,11 +25,11 @@ public CustomerServices() throws SQLException { public void depositMoney(String customerName, int depositAmount) throws SQLException { - int returnedId = dbrepository.findCustomerByUsername(customerName); - Customer customer = dbrepository.returnRecord(returnedId); + int returnedId = customerentityrepository.findCustomerByUsername(customerName); + Customer customer = customerentityrepository.returnRecord(returnedId); int oldAmount = customer.moneyInCents(); int newAmount = transactions.receiveMoneyTransaction(oldAmount, depositAmount); - boolean fundsupdated = dbrepository.updateCustomerFunds(returnedId, newAmount); + boolean fundsupdated = customerentityrepository.updateCustomerFunds(returnedId, newAmount); if (fundsupdated){ System.out.println(customerName + " money was updated!"); logger.info("{} money was updated by {}! ", customerName, depositAmount); @@ -36,8 +37,8 @@ public void depositMoney(String customerName, int depositAmount) throws SQLExcep } public void makeTransfer(String nameSenderCustomer, String nameReceiverCustomer, int amountToSend) throws SQLException, IOException { - int senderreturnedId = dbrepository.findCustomerByUsername(nameSenderCustomer); - int receiverreturnedId = dbrepository.findCustomerByUsername(nameReceiverCustomer); + int senderreturnedId = customerentityrepository.findCustomerByUsername(nameSenderCustomer); + int receiverreturnedId = customerentityrepository.findCustomerByUsername(nameReceiverCustomer); boolean isMoneyReceived = false; @@ -58,13 +59,13 @@ public void makeTransfer(String nameSenderCustomer, String nameReceiverCustomer, public boolean sendMoneyToSomeone(int senderreturnedId, int amountToSend) throws SQLException { - Customer sendercustomer = dbrepository.returnRecord(senderreturnedId); + Customer sendercustomer = customerentityrepository.returnRecord(senderreturnedId); int senderMoney = sendercustomer.moneyInCents(); boolean hasenough = transactions.checkIfCustomerHasFundsToMakeTransaction(senderMoney, amountToSend); if (hasenough) { int newsenderamount = transactions.sendMoneyTransaction(senderMoney, amountToSend); - dbrepository.updateCustomerFunds(senderreturnedId, newsenderamount); + customerentityrepository.updateCustomerFunds(senderreturnedId, newsenderamount); return true; } else @@ -74,10 +75,10 @@ public boolean sendMoneyToSomeone(int senderreturnedId, int amountToSend) throws public boolean receiveMoney(int receiverreturnedId, int amountToSend) throws SQLException { - Customer receivercustomer = dbrepository.returnRecord(receiverreturnedId); + Customer receivercustomer = customerentityrepository.returnRecord(receiverreturnedId); int receiverMoney = receivercustomer.moneyInCents(); int newreceiveramount = transactions.receiveMoneyTransaction(receiverMoney, amountToSend); - boolean receiverFundsUpdated = dbrepository.updateCustomerFunds(receiverreturnedId, newreceiveramount); + boolean receiverFundsUpdated = customerentityrepository.updateCustomerFunds(receiverreturnedId, newreceiveramount); if (receiverFundsUpdated) { return true; } else return false; @@ -89,7 +90,7 @@ public void updateDbAfterTransfer(int senderreturnedId, String nameSenderCustome dbrepository.insertReceiverSenderIntoTransferTotals(senderreturnedId, receiverreturnedId, amountToSend); dbrepository.createTransactionAudit(senderreturnedId, nameSenderCustomer, amountToSend, receiverreturnedId, nameReceiverCustomer); - boolean isfriends = dbrepository.checkIfHasFriend(senderreturnedId, receiverreturnedId); + boolean isfriends = customerentityrepository.checkIfHasFriend(senderreturnedId, receiverreturnedId); if (isfriends){ dbrepository.insertIntoTransfers(senderreturnedId, receiverreturnedId, amountToSend); } @@ -99,8 +100,8 @@ public void convertMyFundsToAllCurrencies(String nameCustomer) throws IOExceptio CurrencyAPI currencyapi = new CurrencyAPI(); HashMap currencies = currencyapi.getCurrencies(); - int customerId = dbrepository.findCustomerByUsername(nameCustomer); - Customer returnedCustomerObj = dbrepository.returnRecord(customerId); + int customerId = customerentityrepository.findCustomerByUsername(nameCustomer); + Customer returnedCustomerObj = customerentityrepository.returnRecord(customerId); int customerFunds = returnedCustomerObj.moneyInCents(); System.out.println(customerFunds + "\n"); for (Object i : currencies.keySet()) { diff --git a/src/main/java/org/example/TransfersApplication.java b/src/main/java/org/example/TransfersApplication.java new file mode 100644 index 0000000..6fe8dc3 --- /dev/null +++ b/src/main/java/org/example/TransfersApplication.java @@ -0,0 +1,12 @@ +package org.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TransfersApplication { + + public static void main(String[] args) { + SpringApplication.run(TransfersApplication.class, args); + } +} diff --git a/src/main/resources/db/migration/V2__create_transaction_category.sql b/src/main/resources/db/migration/V2__create_transaction_category.sql new file mode 100644 index 0000000..7e20fd7 --- /dev/null +++ b/src/main/resources/db/migration/V2__create_transaction_category.sql @@ -0,0 +1,5 @@ +CREATE TABLE transaction_category ( + id SERIAL PRIMARY KEY, + code VARCHAR(20) UNIQUE NOT NULL, + name TEXT NOT NULL +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__add_debitcard_to_customers.sql b/src/main/resources/db/migration/V3__add_debitcard_to_customers.sql new file mode 100644 index 0000000..2e4c721 --- /dev/null +++ b/src/main/resources/db/migration/V3__add_debitcard_to_customers.sql @@ -0,0 +1,2 @@ +ALTER TABLE customers +ADD COLUMN debit_card BOOLEAN NOT NULL DEFAULT FALSE \ No newline at end of file diff --git a/src/test/java/org/example/Controller/DBRepositoryTest.java b/src/test/java/org/example/Controller/DBRepositoryTest.java index 2deb92d..31f01be 100644 --- a/src/test/java/org/example/Controller/DBRepositoryTest.java +++ b/src/test/java/org/example/Controller/DBRepositoryTest.java @@ -1,6 +1,7 @@ package org.example.Controller; -import org.example.DBRepository; +import org.example.Repositories.CustomerEntityRepository; +import org.example.Repositories.TransfersRepository; import org.example.Model.Customer; import org.junit.Test; @@ -12,8 +13,8 @@ public class DBRepositoryTest { - DBRepository dbcontroller = new DBRepository(); - + CustomerEntityRepository customerentityrepository = new CustomerEntityRepository(); + TransfersRepository dbrepository = new TransfersRepository(); public DBRepositoryTest() throws SQLException { } @@ -23,7 +24,7 @@ public void addCustomerRecordTest() throws SQLException { String name = "jennifer"; int money = 18500; String password = "pass4"; - dbcontroller.addCustomerRecord(name,money, password); + customerentityrepository.addCustomerRecord(name,money, password); // assertThat(recordadded).isTrue(); @@ -38,7 +39,7 @@ public void returnRecord() throws SQLException { // String getpassword = customer.getPassword(); // int getmoney = customer.getMoneyInCents(); - Customer returnedCustomer = dbcontroller.returnRecord(customerId); + Customer returnedCustomer = customerentityrepository.returnRecord(customerId); String nickname = returnedCustomer.user(); assertThat(nickname).isEqualTo("johnny"); @@ -51,7 +52,7 @@ public void updateCustomerFundsTest(){ int customerId = 2; int newAmount = 27000; - dbcontroller.updateCustomerFunds(customerId, newAmount); + customerentityrepository.updateCustomerFunds(customerId, newAmount); } @@ -61,7 +62,7 @@ public void findCustomerByUsernameTest() { String name = "jennifer"; - int returnedId = dbcontroller.findCustomerByUsername(name); + int returnedId = customerentityrepository.findCustomerByUsername(name); assertThat(returnedId).isEqualTo(8); @@ -72,12 +73,12 @@ public void insertIntoFriendshipsTest() throws SQLException { int senderId = 5; int receiverId = 3; - dbcontroller.insertIntoFriendships(senderId, receiverId); + dbrepository.insertIntoFriendships(senderId, receiverId); } @Test public void checkIfHasFriendTest() throws SQLException { - boolean isfriend = dbcontroller.checkIfHasFriend(7, 5); + boolean isfriend = customerentityrepository.checkIfHasFriend(7, 5); // fix this, now it is only one way check assertThat(isfriend).isTrue(); } diff --git a/src/test/java/org/example/Controller/TransferCalculatorTest.java b/src/test/java/org/example/Controller/TransferCalculatorTest.java index 273435d..a8b2380 100644 --- a/src/test/java/org/example/Controller/TransferCalculatorTest.java +++ b/src/test/java/org/example/Controller/TransferCalculatorTest.java @@ -1,6 +1,6 @@ package org.example.Controller; -import org.example.DBRepository; +import org.example.Repositories.TransfersRepository; import org.example.Model.TransactionAudit; import org.junit.Test; @@ -17,7 +17,7 @@ public class TransferCalculatorTest { @Test public void returnAuditRecordTest() throws SQLException { - DBRepository dbcontroller = new DBRepository(); + TransfersRepository dbcontroller = new TransfersRepository(); TransactionAudit returnedAudit = dbcontroller.returnTransactionAudit(1);