From a040ff0c132335a079b08f8649513153083454d2 Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Fri, 2 Dec 2022 20:35:36 -0500 Subject: [PATCH 1/6] [*] Revamped MySQLDatabaseGateway and the corresponding tests so that they don't depend on QueryEntryData and QueryBillData anymore. All the "Intermediate" temporary classes are removed. Moved QueryUserData into Entities --- .../database/MySQLDatabaseGateway.java | 207 +++++++++--------- .../billgates/database/QueryBillData.java | 26 --- .../java/billgates/database/QueryEntry.java | 125 ----------- .../billgates/database/QueryEntryData.java | 70 ------ .../database/QuerySplitBillData.java | 26 --- .../database/QuerySplitEntryData.java | 83 ------- .../java/billgates/entities/EntryBuilder.java | 4 +- .../{database => entities}/QueryUserData.java | 2 +- .../interface_adapters/DatabaseGateway.java | 53 ++--- .../alter_entry/AlterEntryRequestModel.java | 2 - .../use_cases/user_join/UserJoinUseCase.java | 2 +- .../database/MySQLDatabaseGatewayTests.java | 111 +++++----- 12 files changed, 201 insertions(+), 510 deletions(-) delete mode 100644 src/main/java/billgates/database/QueryBillData.java delete mode 100644 src/main/java/billgates/database/QueryEntry.java delete mode 100644 src/main/java/billgates/database/QueryEntryData.java delete mode 100644 src/main/java/billgates/database/QuerySplitBillData.java delete mode 100644 src/main/java/billgates/database/QuerySplitEntryData.java rename src/main/java/billgates/{database => entities}/QueryUserData.java (97%) diff --git a/src/main/java/billgates/database/MySQLDatabaseGateway.java b/src/main/java/billgates/database/MySQLDatabaseGateway.java index d3a3531..8536d27 100644 --- a/src/main/java/billgates/database/MySQLDatabaseGateway.java +++ b/src/main/java/billgates/database/MySQLDatabaseGateway.java @@ -1,7 +1,10 @@ package billgates.database; +import billgates.entities.*; import billgates.interface_adapters.DatabaseGateway; +import billgates.entities.EntryBuilder; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -119,7 +122,7 @@ public List getUserData() { } @Override - public QueryBillData getBillData(int billId) { + public List getBillData(int billId) { Instant instantStart = Instant.ofEpochMilli(0); // This is the date of the end of the world @@ -134,8 +137,8 @@ public QueryBillData getBillData(int billId) { } @Override - public QuerySplitBillData getSplitBillData(int splitBillId) { - List entries = new ArrayList<>(); + public List getSplitBillData(int splitBillId) { + List entries = new ArrayList<>(); try { Statement statement = connection.createStatement(); @@ -158,12 +161,12 @@ public QuerySplitBillData getSplitBillData(int splitBillId) { throw new RuntimeException(e); } - return new QuerySplitBillData(splitBillId, entries); + return entries; } @Override - public QueryBillData getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate) { - List entries = new ArrayList<>(); + public List getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate) { + List entries = new ArrayList<>(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); try { @@ -188,11 +191,11 @@ WHERE date BETWEEN CAST('%s' AS DATETIME) AND CAST('%s' AS DATETIME) throw new RuntimeException(e); } - return new QueryBillData(billId, entries); + return entries; } @Override - public QueryEntryData getEntryData(int billId, int entryId) { + public Entry getEntryData(int billId, int entryId) { int splitBillId; double value; String currency; @@ -238,19 +241,21 @@ public QueryEntryData getEntryData(int billId, int entryId) { throw new RuntimeException(e); } - return new QueryEntryData(entryId, - zDate, - value, - currency, - description, - from, - to, - location, - splitBillId); + return new EntryBuilder() + .setId(entryId) + .setValue(value) + .setDate(zDate) + .setCurrency(currency) + .setDescription(description) + .setFrom(from) + .setTo(to) + .setLocation(location) + .setSplitterBillId(splitBillId) + .buildEntry(); } @Override - public QuerySplitEntryData getSplitEntryData(int billId, int entryId) { + public SplitterEntry getSplitEntryData(int billId, int entryId) { double value; String currency; String description; @@ -298,20 +303,22 @@ public QuerySplitEntryData getSplitEntryData(int billId, int entryId) { throw new RuntimeException(e); } - return new QuerySplitEntryData(entryId, - zDate, - value, - currency, - description, - from, - to, - location, - payee, - isPaidBack); + return new EntryBuilder() + .setId(entryId) + .setValue(value) + .setDate(zDate) + .setCurrency(currency) + .setDescription(description) + .setFrom(from) + .setTo(to) + .setLocation(location) + .setPayee(payee) + .setIsPaidBack(isPaidBack) + .buildSplitterEntry(); } @Override - public void insertEntry(int billId, QueryEntryData entry) { + public void insertEntry(int billId, Entry entry) { try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -320,22 +327,22 @@ public void insertEntry(int billId, QueryEntryData entry) { String query; // This is the case where we don't want autoincrement - if (!(entry.getId() == -1)) { + if (!(entry.getId().getAttribute() == -1)) { query = String.format(""" INSERT INTO bill_%d (entry_id, value, date, currency, description, `from`, `to`, location, split_bill_id) VALUE ( %d, %f, "%s", "%s", "%s", "%s", "%s", "%s", %d ) """, billId, - entry.getId(), - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getSplitBillId()); + entry.getId().getAttribute(), + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getSplitterBillId().getAttribute()); } else { // This is the case where we want auto increment query = String.format(""" @@ -344,14 +351,14 @@ public void insertEntry(int billId, QueryEntryData entry) { ) """, billId, - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getSplitBillId()); + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getSplitterBillId().getAttribute()); } statement.execute(query); @@ -362,7 +369,7 @@ public void insertEntry(int billId, QueryEntryData entry) { } @Override - public void insertSplitEntry(int billId, QuerySplitEntryData entry) { + public void insertSplitEntry(int billId, SplitterEntry entry) { try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -371,7 +378,7 @@ public void insertSplitEntry(int billId, QuerySplitEntryData entry) { String query; // This is the case where we don't want autoincrement - if (!(entry.getId() == -1)) { + if (!(entry.getId().getAttribute() == -1)) { query = String.format(""" INSERT INTO bill_%d_%d (entry_id, value, date, currency, description, `from`, `to`, location, payee, paid_back) VALUE ( %d, %f, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s" @@ -379,16 +386,16 @@ public void insertSplitEntry(int billId, QuerySplitEntryData entry) { """, this.userId, billId, - entry.getId(), - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getPayee(), - entry.getIsPaidBack()); + entry.getId().getAttribute(), + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getPayee().getAttribute(), + entry.getIsPaidBack().getAttribute()); } else { // This is the case where we want auto increment query = String.format(""" @@ -398,15 +405,15 @@ public void insertSplitEntry(int billId, QuerySplitEntryData entry) { """, this.userId, billId, - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getPayee(), - entry.getIsPaidBack()); + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getPayee().getAttribute(), + entry.getIsPaidBack().getAttribute()); } statement.execute(query); @@ -546,7 +553,7 @@ public void modifySplitEntry(int billId, int entryId, String column, String newV } @Override - public void modifyEntry(int billId, QueryEntryData entry) { + public void modifyEntry(int billId, Entry entry) { try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -566,15 +573,15 @@ public void modifyEntry(int billId, QueryEntryData entry) { split_bill_id = %d WHERE entry_id = %d """, billId, - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getSplitBillId(), - entry.getId()); + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getSplitterBillId().getAttribute(), + entry.getId().getAttribute()); statement.execute(query); @@ -584,7 +591,7 @@ public void modifyEntry(int billId, QueryEntryData entry) { } @Override - public void modifySplitEntry(int billId, QuerySplitEntryData entry) { + public void modifySplitEntry(int billId, SplitterEntry entry) { try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -606,16 +613,16 @@ public void modifySplitEntry(int billId, QuerySplitEntryData entry) { WHERE entry_id = %d """, this.userId, billId, - entry.getValue(), - entry.getDate().format(formatter), - entry.getCurrency(), - entry.getDescription(), - entry.getFrom(), - entry.getTo(), - entry.getLocation(), - entry.getPayee(), - entry.getIsPaidBack(), - entry.getId()); + entry.getValue().getAttribute(), + entry.getDate().getAttribute().format(formatter), + entry.getCurrency().getAttribute(), + entry.getDescription().getAttribute(), + entry.getFrom().getAttribute(), + entry.getTo().getAttribute(), + entry.getLocation().getAttribute(), + entry.getPayee().getAttribute(), + entry.getIsPaidBack().getAttribute(), + entry.getId().getAttribute()); statement.execute(query); @@ -688,18 +695,8 @@ public void createUsersTable() { try { Statement statement = connection.createStatement(); - String checkQuery = "SHOW TABLES LIKE 'users'"; - - ResultSet resultSet = statement.executeQuery(checkQuery); - - // Checks if the table already exists, if not, continue creating the table - if (resultSet.next()) { - return; - } - - String query = """ - CREATE TABLE users + CREATE TABLE IF NOT EXISTS users ( user_id INT AUTO_INCREMENT PRIMARY KEY, @@ -721,4 +718,14 @@ public void setUserId(int userId) { this.userId = userId; } + public static void main(String[] args) { + MySQLDatabaseGateway testGateway = new MySQLDatabaseGateway(); + + testGateway.setUserId(9999); + + Entry obtainedEntry = testGateway.getEntryData(9999, 1); + + System.out.println(obtainedEntry.getDescription().getAttribute()); + } + } diff --git a/src/main/java/billgates/database/QueryBillData.java b/src/main/java/billgates/database/QueryBillData.java deleted file mode 100644 index bc4c524..0000000 --- a/src/main/java/billgates/database/QueryBillData.java +++ /dev/null @@ -1,26 +0,0 @@ -package billgates.database; - -import java.util.List; - -/** - * Clean Architecture Layer: Application Business Rules - * - * @author Ray, Scott - */ -public class QueryBillData { - private final int billId; - private final List entries; - - public QueryBillData(int billId, List entries) { - this.billId = billId; - this.entries = entries; - } - - public int getBillId() { - return billId; - } - - public List getEntries() { - return entries; - } -} diff --git a/src/main/java/billgates/database/QueryEntry.java b/src/main/java/billgates/database/QueryEntry.java deleted file mode 100644 index f1ff08f..0000000 --- a/src/main/java/billgates/database/QueryEntry.java +++ /dev/null @@ -1,125 +0,0 @@ -package billgates.database; - -import billgates.entities.EntryBuilder; - -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; - -public class QueryEntry { - -/** - * Clean Architecture Layer: Application Business Rules - * This is the class for the general Entry - * @author Ray - */ - private int id = -1; - private final ZonedDateTime date; - private final double value; - private String currency = ""; - private String description = ""; - private String from = ""; - private String to = ""; - private String location = ""; - - public QueryEntry(int id, - ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location) { - this.id = id; - this.date = date.truncatedTo(ChronoUnit.SECONDS); - this.value = value; - this.currency = currency; - this.description = description; - this.from = from; - this.to = to; - this.location = location; - } - - public QueryEntry(ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location) { - this.date = date.truncatedTo(ChronoUnit.SECONDS); - this.value = value; - this.currency = currency; - this.description = description; - this.from = from; - this.to = to; - this.location = location; - } - - public QueryEntry(int id, - ZonedDateTime date, - double value) { - // Constructor for not all values provided - this.id = id; - this.date = date.truncatedTo(ChronoUnit.SECONDS); - this.value = value; - } - - public QueryEntry(ZonedDateTime date, - double value) { - // Constructor for not all values provided, with no ID provided - this.date = date.truncatedTo(ChronoUnit.SECONDS); - this.value = value; - } - - public EntryBuilder toEntryBuilder() { - return new EntryBuilder() - .setId(this.id) - .setDate(this.date) - .setValue(this.value) - .setCurrency(this.currency) - .setDescription(this.description) - .setFrom(this.from) - .setTo(this.to) - .setLocation(this.location); - } - - public int getId() { return id; } - - public ZonedDateTime getDate() { - return date; - } - - public double getValue() { - return value; - } - - public String getCurrency() { - return currency; - } - - public String getDescription() { - return description; - } - - public String getFrom() { - return from; - } - - public String getTo() { - return to; - } - - public String getLocation() { - return location; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || this.getClass() != obj.getClass()) return false; - - billgates.database.QueryEntry entry = (billgates.database.QueryEntry) obj; - return this.getId() == entry.getId(); - } - -} \ No newline at end of file diff --git a/src/main/java/billgates/database/QueryEntryData.java b/src/main/java/billgates/database/QueryEntryData.java deleted file mode 100644 index bb55805..0000000 --- a/src/main/java/billgates/database/QueryEntryData.java +++ /dev/null @@ -1,70 +0,0 @@ -package billgates.database; - -import billgates.entities.EntryBuilder; - -import java.time.ZonedDateTime; - -/** - * Clean Architecture Layer: Application Business Rules - * - * @author Ray - */ -public class QueryEntryData extends QueryEntry{ - private int splitBillId = -1; - - public QueryEntryData(int id, - ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location, - int splitBillId) { - super(id, date, value, currency, description, from, to, location); - this.splitBillId = splitBillId; - } - - public QueryEntryData(ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location, - int splitBillId) { - super(date, value, currency, description, from, to, location); - this.splitBillId = splitBillId; - } - - public QueryEntryData(int id, - ZonedDateTime date, - double value) { - // Constructor for not all values provided - super(id, date, value); - } - - public QueryEntryData(ZonedDateTime date, - double value) { - // Constructor for not all values provided, with no ID provided - super(date, value); - } - - public EntryBuilder toEntryBuilder() { - return new EntryBuilder() - .setId(this.getId()) - .setDate(this.getDate()) - .setValue(this.getValue()) - .setCurrency(this.getCurrency()) - .setDescription(this.getDescription()) - .setFrom(this.getFrom()) - .setTo(this.getTo()) - .setLocation(this.getLocation()) - .setSplitterBillId(this.getSplitBillId()); - } - - public int getSplitBillId() { - return splitBillId; - } - -} diff --git a/src/main/java/billgates/database/QuerySplitBillData.java b/src/main/java/billgates/database/QuerySplitBillData.java deleted file mode 100644 index 6818685..0000000 --- a/src/main/java/billgates/database/QuerySplitBillData.java +++ /dev/null @@ -1,26 +0,0 @@ -package billgates.database; - -import java.util.List; - -/** - * Clean Architecture Layer: Application Business Rules - * - * @author Ray, Scott - */ -public class QuerySplitBillData { - private final int splitBillId; - private final List splitEntries; - - public QuerySplitBillData(int billId, List splitEntries) { - this.splitBillId = billId; - this.splitEntries = splitEntries; - } - - public int getBillId() { - return splitBillId; - } - - public List getEntries() { - return splitEntries; - } -} diff --git a/src/main/java/billgates/database/QuerySplitEntryData.java b/src/main/java/billgates/database/QuerySplitEntryData.java deleted file mode 100644 index d0b2847..0000000 --- a/src/main/java/billgates/database/QuerySplitEntryData.java +++ /dev/null @@ -1,83 +0,0 @@ -package billgates.database; - -import billgates.entities.EntryBuilder; - -import java.time.ZonedDateTime; - -/** - * Clean Architecture Layer: Application Business Rules - * - * Note: The entry_id that is in this case is the entry_id of the splitter bill - * IT IS NOT THE SAME AS THE ORIGINAL ENTRY THAT WE SPLITTED ON - * @author Ray - */ -public class QuerySplitEntryData extends QueryEntry{ - private String payee = ""; - private boolean isPaidBack = false; - - public QuerySplitEntryData(int id, - ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location, - String payee, - boolean isPaidBack) { - super(id, date, value, currency, description, from, to, location); - this.payee = payee; - this.isPaidBack = isPaidBack; - - } - - public QuerySplitEntryData(ZonedDateTime date, - double value, - String currency, - String description, - String from, - String to, - String location, - String payee, - boolean isPaidBack) { - super(date, value, currency, description, from, to, location); - this.payee = payee; - this.isPaidBack = isPaidBack; - } - - public QuerySplitEntryData(int id, - ZonedDateTime date, - double value) { - // Constructor for not all values provided - super(id, date, value); - } - - public QuerySplitEntryData(ZonedDateTime date, - double value) { - // Constructor for not all values provided, with no ID provided - super(date, value); - } - - public String getPayee() { - return this.payee; - } - - public boolean getIsPaidBack() { - return this.isPaidBack; - } - - public EntryBuilder toEntryBuilder() { - return new EntryBuilder() - .setId(this.getId()) - .setDate(this.getDate()) - .setValue(this.getValue()) - .setCurrency(this.getCurrency()) - .setDescription(this.getDescription()) - .setFrom(this.getFrom()) - .setTo(this.getTo()) - .setLocation(this.getLocation()) - .setPayee(this.getPayee()) - .setIsPaidBack(this.getIsPaidBack()); - } - -} diff --git a/src/main/java/billgates/entities/EntryBuilder.java b/src/main/java/billgates/entities/EntryBuilder.java index cf394c4..6200822 100644 --- a/src/main/java/billgates/entities/EntryBuilder.java +++ b/src/main/java/billgates/entities/EntryBuilder.java @@ -1,6 +1,7 @@ package billgates.entities; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; /** * Clean Architecture Layer: Enterprise Business Rules @@ -87,7 +88,8 @@ public EntryBuilder setId(int id) { } public EntryBuilder setDate(ZonedDateTime date) { - this.date = date; + // Truncates the date unit to only seconds + this.date = date.truncatedTo(ChronoUnit.SECONDS); return this; } diff --git a/src/main/java/billgates/database/QueryUserData.java b/src/main/java/billgates/entities/QueryUserData.java similarity index 97% rename from src/main/java/billgates/database/QueryUserData.java rename to src/main/java/billgates/entities/QueryUserData.java index f8d4143..f93bd60 100644 --- a/src/main/java/billgates/database/QueryUserData.java +++ b/src/main/java/billgates/entities/QueryUserData.java @@ -1,4 +1,4 @@ -package billgates.database; +package billgates.entities; import java.util.List; diff --git a/src/main/java/billgates/interface_adapters/DatabaseGateway.java b/src/main/java/billgates/interface_adapters/DatabaseGateway.java index db5257c..6ce5698 100644 --- a/src/main/java/billgates/interface_adapters/DatabaseGateway.java +++ b/src/main/java/billgates/interface_adapters/DatabaseGateway.java @@ -1,6 +1,9 @@ package billgates.interface_adapters; import billgates.database.*; +import billgates.entities.Entry; +import billgates.entities.QueryUserData; +import billgates.entities.SplitterEntry; import java.time.ZonedDateTime; import java.util.List; @@ -42,19 +45,19 @@ public interface DatabaseGateway { * Obtains information from the whole bill table associated with the billId * * @param billId the billId that we wish to query - * @return a QueryBillData that encapsulates all the QueryEntryData within it - * @see QueryBillData + * @return a list of Entry objects + * @see Entry */ - QueryBillData getBillData(int billId); + List getBillData(int billId); /** * Obtains information from the whole Split Bill table associated with splitBillId * * @param splitBillId the splitBillId that we wish to query - * @return a QuerySplitBillData that encapsulates all the QuerySplitEntryData within it - * @see QuerySplitBillData + * @return a list of SplitterEntry objects + * @see billgates.entities.SplitterEntry */ - QuerySplitBillData getSplitBillData(int splitBillId); + List getSplitBillData(int splitBillId); /** * Obtains information from the whole bill table associated with the billId @@ -63,54 +66,54 @@ public interface DatabaseGateway { * @param billId the bill ID that we are trying to obtain information from * @param startDate a ZonedDateTime object that marks the start date of this query * @param endDate a ZonedDateTime object that marks the end date of this query - * @return a QueryBillData that encapsulates all the QueryEntryData within the date range - * @see QueryBillData + * @return a list of Entry that is within the specified date range + * @see billgates.entities.Entry */ - QueryBillData getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate); + List getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate); /** * Obtains information from a specific entry (using entryId) * in a specific bill (using billId) - * the result information is bundled by QueryEntryData class + * the result information is bundled by the Entry class * * @param billId the bill ID that we are trying to obtain the entry from * @param entryId the entry ID that we are trying to obtain information from - * @return a QueryEntryData that contains the information of the entry queried + * @return an Entry with the information * returns null if the entry_id being queried doesn't exist in the bill - * @see QueryEntryData + * @see Entry */ - QueryEntryData getEntryData(int billId, int entryId); + Entry getEntryData(int billId, int entryId); /** * Obtains information from a specific entry (using entryId, THE ID OF THE SPLIT ENTRY) * in a specific SPLIT bill (using billId) - * the result entry information is bundled by QuerySplitEntryData class + * the result entry information is bundled by SplitterEntry class * * @param billId the bill ID that we are trying to obtain the entry from * @param entryId the entry ID that we are trying to obtain information from - * @return a QueryEntryData that contains the information of the entry queried + * @return a SplitterEntry that contains the information of the entry queried * returns null if the entry_id being queried doesn't exist in the bill - * @see QuerySplitEntryData + * @see SplitterEntry */ - QuerySplitEntryData getSplitEntryData(int billId, int entryId); + SplitterEntry getSplitEntryData(int billId, int entryId); /** * Inserts the entry into the specified bill (using billId) in the database * * @param billId the bill ID that we are trying to insert the entry into - * @param entry the QueryEntryData that we are trying to insert - * @see QueryEntryData + * @param entry the Entry that we are trying to insert + * @see Entry */ - void insertEntry(int billId, QueryEntryData entry); + void insertEntry(int billId, Entry entry); /** * Inserts the SPLIT entry into the specified SPLIT bill (using billId) in the database * * @param billId the SPLIT bill ID that we are trying to insert the entry into - * @param entry the QuerySplitEntryData that we are trying to insert - * @see QuerySplitEntryData + * @param entry the SplitterEntry that we are trying to insert + * @see SplitterEntry */ - void insertSplitEntry(int billId, QuerySplitEntryData entry); + void insertSplitEntry(int billId, SplitterEntry entry); /** * Inserts the user into the users table in the database @@ -165,7 +168,7 @@ public interface DatabaseGateway { * @param billId the id of the bill that we are trying to modify the specific entry from * @param entry a QueryEntryData object that contains all the information of the new entry */ - void modifyEntry(int billId, QueryEntryData entry); + void modifyEntry(int billId, Entry entry); /** * Overwrites the SPLIT entry completely with the SPLIT entry_id contained in entry @@ -174,7 +177,7 @@ public interface DatabaseGateway { * @param billId the id of the SPLIT bill that we are trying to modify the specific entry from * @param entry a QuerySplitEntryData object that contains all the information of the new entry */ - void modifySplitEntry(int billId, QuerySplitEntryData entry); + void modifySplitEntry(int billId, SplitterEntry entry); /** * Creates a bill with the table name "bill_{billId}" in our database diff --git a/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java b/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java index aa55556..d08699a 100644 --- a/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java +++ b/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java @@ -1,7 +1,5 @@ package billgates.use_cases.alter_entry; -import billgates.database.QueryEntryData; - import java.time.ZonedDateTime; /** diff --git a/src/main/java/billgates/use_cases/user_join/UserJoinUseCase.java b/src/main/java/billgates/use_cases/user_join/UserJoinUseCase.java index ae9c1d4..1842e3d 100644 --- a/src/main/java/billgates/use_cases/user_join/UserJoinUseCase.java +++ b/src/main/java/billgates/use_cases/user_join/UserJoinUseCase.java @@ -1,6 +1,6 @@ package billgates.use_cases.user_join; -import billgates.database.QueryUserData; +import billgates.entities.QueryUserData; import billgates.entities.User; import billgates.interface_adapters.DatabaseGateway; diff --git a/src/test/java/database/MySQLDatabaseGatewayTests.java b/src/test/java/database/MySQLDatabaseGatewayTests.java index bf6fda8..642a2e7 100644 --- a/src/test/java/database/MySQLDatabaseGatewayTests.java +++ b/src/test/java/database/MySQLDatabaseGatewayTests.java @@ -1,5 +1,8 @@ package database; +import billgates.entities.Entry; +import billgates.entities.EntryBuilder; +import billgates.entities.QueryUserData; import org.junit.*; import static org.junit.Assert.*; import billgates.database.*; @@ -68,7 +71,7 @@ public void setUp() { testStatement.execute(deleteUserQuery); } - // For each test, I want a table called bill9999 + // For each test, I want a table called bill_9999 String createTableQuery = String.format(""" CREATE TABLE bill_%d ( @@ -337,22 +340,24 @@ public void testInsertEntryAllAttributes() { String testLocation = "Online"; int testSplitBillID = -1; - QueryEntryData testEntry3 = new QueryEntryData(testID, - testDate, - testValue, - testCurrency, - testDescription, - testFrom, - testTo, - testLocation, - testSplitBillID); + Entry testEntry3 = new EntryBuilder() + .setId(testID) + .setDate(testDate) + .setValue(testValue) + .setCurrency(testCurrency) + .setDescription(testDescription) + .setFrom(testFrom) + .setTo(testTo) + .setLocation(testLocation) + .setSplitterBillId(testSplitBillID) + .buildEntry(); this.testGateway.insertEntry(this.testBillID, testEntry3); Statement testStatement = this.testConnection.createStatement(); String getNewlyCreatedEntry = String.format("SELECT * FROM bill_%d WHERE entry_id = %d", - this.testBillID, testEntry3.getId()); + this.testBillID, testEntry3.getId().getAttribute()); ResultSet result = testStatement.executeQuery(getNewlyCreatedEntry); @@ -415,16 +420,18 @@ public void testInsertEntryMainAttributes() { ZoneId.systemDefault()); double testValue = 999.1; - QueryEntryData testEntry4 = new QueryEntryData(testID, - testDate, - testValue); + Entry testEntry4 = new EntryBuilder() + .setId(testID) + .setDate(testDate) + .setValue(testValue) + .buildEntry(); this.testGateway.insertEntry(this.testBillID, testEntry4); Statement testStatement = this.testConnection.createStatement(); String getNewlyCreatedEntry = String.format("SELECT * FROM bill_%d WHERE entry_id = %d", - this.testBillID, testEntry4.getId()); + this.testBillID, testEntry4.getId().getAttribute()); ResultSet result = testStatement.executeQuery(getNewlyCreatedEntry); @@ -486,8 +493,10 @@ public void testInsertEntryAutoIncrement() { ZoneId.systemDefault()); double testValue = 1011.02; - QueryEntryData testEntry5 = new QueryEntryData(testDate, - testValue); + Entry testEntry5 = new EntryBuilder() + .setDate(testDate) + .setValue(testValue) + .buildEntry(); this.testGateway.insertEntry(this.testBillID, testEntry5); @@ -518,7 +527,7 @@ public void testInsertEntryAutoIncrement() { public void testGetEntry() { try { // In the @Before chunk, we inserted an entry that has the ID 1 - QueryEntryData obtainedEntry = this.testGateway.getEntryData(this.testBillID, 1); + Entry obtainedEntry = this.testGateway.getEntryData(this.testBillID, 1); ZonedDateTime expectedDate = ZonedDateTime.of(1970, 1, @@ -530,15 +539,15 @@ public void testGetEntry() { // This information was identical to the ones in the setUp chunk. // (1, 123.45, "1970-01-02 00:00:00", "CAD", "This is a test entry", "Credit Card", "T&T Supermarket", "T&T Supermarket", -1) - assertEquals(1, obtainedEntry.getId()); - assertEquals(expectedDate, obtainedEntry.getDate()); - assertEquals(123.45, obtainedEntry.getValue(), 1e-8); - assertEquals("CAD", obtainedEntry.getCurrency()); - assertEquals("This is a test entry", obtainedEntry.getDescription()); - assertEquals("Credit Card", obtainedEntry.getFrom()); - assertEquals("T&T Supermarket", obtainedEntry.getTo()); - assertEquals("T&T Supermarket", obtainedEntry.getLocation()); - assertEquals(-1, obtainedEntry.getSplitBillId()); + assertEquals(1, (int) obtainedEntry.getId().getAttribute()); + assertEquals(expectedDate, obtainedEntry.getDate().getAttribute()); + assertEquals(123.45, obtainedEntry.getValue().getAttribute(), 1e-8); + assertEquals("CAD", obtainedEntry.getCurrency().getAttribute()); + assertEquals("This is a test entry", obtainedEntry.getDescription().getAttribute()); + assertEquals("Credit Card", obtainedEntry.getFrom().getAttribute()); + assertEquals("T&T Supermarket", obtainedEntry.getTo().getAttribute()); + assertEquals("T&T Supermarket", obtainedEntry.getLocation().getAttribute()); + assertEquals(-1, (int) obtainedEntry.getSplitterBillId().getAttribute()); } catch (RuntimeException e) { // Fails the test whenever we encounter an Error fail(); @@ -548,11 +557,11 @@ public void testGetEntry() { @Test(timeout = TEST_TIMEOUT) public void testGetBillDataAll() { try { - QueryBillData obtainedBillData = this.testGateway.getBillData(this.testBillID); + List obtainedBillData = this.testGateway.getBillData(this.testBillID); // Testing if the size is 2, since if there is 2, then it means we have obtained all entries // In the setUp chunk, we initialized the bill with 2 entries - assertEquals(obtainedBillData.getEntries().size(), 2); + assertEquals(obtainedBillData.size(), 2); } catch (RuntimeException e) { // Fails the test whenever we encounter an Error @@ -579,10 +588,10 @@ public void testGetBillDataPartial() { 0, 0, ZoneId.systemDefault()); - QueryBillData obtainedBillData = this.testGateway.getBillData(this.testBillID, startTime, endTime); + List obtainedBillData = this.testGateway.getBillData(this.testBillID, startTime, endTime); // If we only have 1 entry obtained, then it is a success - assertEquals(obtainedBillData.getEntries().size(), 1); + assertEquals(obtainedBillData.size(), 1); } catch (RuntimeException e) { // Fails the test whenever we encounter an Error @@ -709,22 +718,24 @@ public void testModifyEntryAll() { String testLocation = "Online"; int testSplitBillID = -1; - QueryEntryData testModifiedEntry1 = new QueryEntryData(testEntryID, - testTime, - testValue, - testCurrency, - testDescription, - testFrom, - testTo, - testLocation, - testSplitBillID); + Entry testModifiedEntry1 = new EntryBuilder() + .setId(testEntryID) + .setDate(testTime) + .setValue(testValue) + .setCurrency(testCurrency) + .setDescription(testDescription) + .setFrom(testFrom) + .setTo(testTo) + .setLocation(testLocation) + .setSplitterBillId(testSplitBillID) + .buildEntry(); this.testGateway.modifyEntry(this.testBillID, testModifiedEntry1); Statement testStatement = this.testConnection.createStatement(); String getModifiedEntry = String.format("SELECT * FROM bill_%d WHERE entry_id = %d", - this.testBillID, testModifiedEntry1.getId()); + this.testBillID, testModifiedEntry1.getId().getAttribute()); ResultSet result = testStatement.executeQuery(getModifiedEntry); @@ -756,15 +767,15 @@ public void testModifyEntryAll() { // We can pass in the different zones we want to convert in, and we can obtain the value we want zDate = ZonedDateTime.ofInstant(i, ZoneId.systemDefault()); - assertEquals(obtainedID, testModifiedEntry1.getId()); - assertEquals(value, testModifiedEntry1.getValue(), 1e-8); - assertEquals(zDate, testModifiedEntry1.getDate()); - assertEquals(currency, testModifiedEntry1.getCurrency()); - assertEquals(description, testModifiedEntry1.getDescription()); - assertEquals(from, testModifiedEntry1.getFrom()); - assertEquals(to, testModifiedEntry1.getTo()); - assertEquals(location, testModifiedEntry1.getLocation()); - assertEquals(splitBillID, testModifiedEntry1.getSplitBillId()); + assertEquals(obtainedID, (int) testModifiedEntry1.getId().getAttribute()); + assertEquals(value, testModifiedEntry1.getValue().getAttribute(), 1e-8); + assertEquals(zDate, testModifiedEntry1.getDate().getAttribute()); + assertEquals(currency, testModifiedEntry1.getCurrency().getAttribute()); + assertEquals(description, testModifiedEntry1.getDescription().getAttribute()); + assertEquals(from, testModifiedEntry1.getFrom().getAttribute()); + assertEquals(to, testModifiedEntry1.getTo().getAttribute()); + assertEquals(location, testModifiedEntry1.getLocation().getAttribute()); + assertEquals(splitBillID, (int) testModifiedEntry1.getSplitterBillId().getAttribute()); } catch (RuntimeException | SQLException e) { // Fails the test whenever we encounter an Error From 57c3d59d344b05aef266ede73fffd085d16631be Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Sat, 3 Dec 2022 01:45:15 -0500 Subject: [PATCH 2/6] [*] Modified EntryBuilder so that it doesn't give the InvalidEntryException. Modified AlterEntryUseCase and related classes and methods to make avoid errors. --- .../java/billgates/entities/EntryBuilder.java | 6 --- .../entities/InvalidEntryException.java | 14 ------ .../alter_entry/AlterEntryRequestModel.java | 32 ++++++++---- .../alter_entry/AlterEntryUseCase.java | 6 +-- .../insert_entry/InsertEntryUseCase.java | 50 ++++++++++++------- 5 files changed, 58 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/billgates/entities/InvalidEntryException.java diff --git a/src/main/java/billgates/entities/EntryBuilder.java b/src/main/java/billgates/entities/EntryBuilder.java index 6200822..b0de995 100644 --- a/src/main/java/billgates/entities/EntryBuilder.java +++ b/src/main/java/billgates/entities/EntryBuilder.java @@ -33,9 +33,6 @@ public EntryBuilder() { } public Entry buildEntry() { - if (this.id == -1) { - throw new InvalidEntryException("Invalid entry ID!"); - } return new Entry( new Attribute<>(this.id, "id"), new Attribute<>(this.date, "date"), @@ -50,9 +47,6 @@ public Entry buildEntry() { } public SplitterEntry buildSplitterEntry() { - if (this.id == -1) { - throw new InvalidEntryException("Invalid entry ID!"); - } return new SplitterEntry( new Attribute<>(this.id, "id"), new Attribute<>(this.date, "date"), diff --git a/src/main/java/billgates/entities/InvalidEntryException.java b/src/main/java/billgates/entities/InvalidEntryException.java deleted file mode 100644 index fbb935f..0000000 --- a/src/main/java/billgates/entities/InvalidEntryException.java +++ /dev/null @@ -1,14 +0,0 @@ -package billgates.entities; - -/** - * Clean Architecture Layer: Enterprise Business Rules - * This exception represents that the program failed to create an entry. - * - * @author Scott - */ -public class InvalidEntryException extends RuntimeException { - - public InvalidEntryException(String reason) { - super("Failed to create an entry: " + reason); - } -} diff --git a/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java b/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java index d08699a..90cc3ac 100644 --- a/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java +++ b/src/main/java/billgates/use_cases/alter_entry/AlterEntryRequestModel.java @@ -1,5 +1,8 @@ package billgates.use_cases.alter_entry; +import billgates.entities.Entry; +import billgates.entities.EntryBuilder; + import java.time.ZonedDateTime; /** @@ -20,14 +23,14 @@ public class AlterEntryRequestModel { private String to; private String location; - public AlterEntryRequestModel(QueryEntryData oldEntry) { - date = oldEntry.getDate(); - value = oldEntry.getValue(); - currency = oldEntry.getCurrency(); - description = oldEntry.getDescription(); - from = oldEntry.getFrom(); - to = oldEntry.getTo(); - location = oldEntry.getLocation(); + public AlterEntryRequestModel(Entry oldEntry) { + date = oldEntry.getDate().getAttribute(); + value = oldEntry.getValue().getAttribute(); + currency = oldEntry.getCurrency().getAttribute(); + description = oldEntry.getDescription().getAttribute(); + from = oldEntry.getFrom().getAttribute(); + to = oldEntry.getTo().getAttribute(); + location = oldEntry.getLocation().getAttribute(); } @@ -68,8 +71,17 @@ public void setCurrency(String currency) { this.currency = currency; } - public QueryEntryData getQueryEntryData(int entryID) { - return new QueryEntryData(date, value, currency, description, from, to, location, -1); + public Entry getEntryData(int entryID) { + return new EntryBuilder() + .setDate(date) + .setValue(value) + .setCurrency(currency) + .setDescription(description) + .setFrom(from) + .setTo(to) + .setLocation(location) + .setSplitterBillId(-1) + .buildEntry(); } } diff --git a/src/main/java/billgates/use_cases/alter_entry/AlterEntryUseCase.java b/src/main/java/billgates/use_cases/alter_entry/AlterEntryUseCase.java index 01da432..796914a 100644 --- a/src/main/java/billgates/use_cases/alter_entry/AlterEntryUseCase.java +++ b/src/main/java/billgates/use_cases/alter_entry/AlterEntryUseCase.java @@ -1,6 +1,6 @@ package billgates.use_cases.alter_entry; -import billgates.database.QueryEntryData; +import billgates.entities.Entry; import billgates.entities.User; import billgates.interface_adapters.DatabaseGateway; @@ -32,7 +32,7 @@ public AlterEntryUseCase(DatabaseGateway gateway) { public void alterEntry(int entryId, Map changeMap) { int billId = User.getInstance().getCurrentBillID(); - QueryEntryData oldEntry = this.gateway.getEntryData(billId, entryId); + Entry oldEntry = this.gateway.getEntryData(billId, entryId); AlterEntryRequestModel model = new AlterEntryRequestModel(oldEntry); for (Map.Entry changeSet : changeMap.entrySet()) { String alterColumn = changeSet.getKey(); @@ -62,7 +62,7 @@ public void alterEntry(int entryId, Map changeMap) { } } - gateway.modifyEntry(billId, model.getQueryEntryData(entryId)); + gateway.modifyEntry(billId, model.getEntryData(entryId)); } diff --git a/src/main/java/billgates/use_cases/insert_entry/InsertEntryUseCase.java b/src/main/java/billgates/use_cases/insert_entry/InsertEntryUseCase.java index 78cda7b..bca101e 100644 --- a/src/main/java/billgates/use_cases/insert_entry/InsertEntryUseCase.java +++ b/src/main/java/billgates/use_cases/insert_entry/InsertEntryUseCase.java @@ -1,7 +1,8 @@ package billgates.use_cases.insert_entry; -import billgates.database.QueryEntryData; -import billgates.database.QuerySplitEntryData; +import billgates.entities.Entry; +import billgates.entities.EntryBuilder; +import billgates.entities.SplitterEntry; import billgates.entities.User; import billgates.interface_adapters.DatabaseGateway; @@ -16,24 +17,39 @@ public InsertEntryUseCase(DatabaseGateway gateway) { @Override public void insertEntry(InsertEntryRequestModel model) { - //Check if we are adding a normal entry to the main bill or a splitter entry to the splitter bill. + // Check if we are adding a normal entry to the main bill or a splitter entry to the splitter bill. if (User.getInstance().getBillId() == User.getInstance().getCurrentBillID()) { - //Construct a QueryEntryData for new entry, and the entry id of it is the size of all entries plus one. - QueryEntryData entry = new QueryEntryData( - model.getDate(), model.getValue(), - model.getCurrency(), model.getDescription(), - model.getFrom(), model.getTo(), model.getLocation(), -1); - - //Pass the new QueryEntryData in the Gateway#insertEntry. + // Construct an entry using the entry builder + // Default with a splitterBillId being -1 + // Default with the entryId with -1 + Entry entry = new EntryBuilder() + .setDate(model.getDate()) + .setValue(model.getValue()) + .setCurrency(model.getCurrency()) + .setDescription(model.getDescription()) + .setFrom(model.getFrom()) + .setTo(model.getTo()) + .setLocation(model.getLocation()) + .setSplitterBillId(-1) + .buildEntry(); + + // Pass the new QueryEntryData in the Gateway#insertEntry. this.gateway.insertEntry(User.getInstance().getCurrentBillID(), entry); } else { - //Construct a QuerySplitEntryData for new splitter entry. - QuerySplitEntryData entry = new QuerySplitEntryData(model.getDate(), - model.getValue(), model.getCurrency(), - model.getDescription(), model.getFrom(), model.getTo(), model.getLocation(), model.getPayee(), - model.getIsPaidBack()); - - //Pass the new QuerySplitEntryData in the Gateway #insertSplitEntry. + // Construct a QuerySplitEntryData for new splitter entry. + SplitterEntry entry = new EntryBuilder() + .setDate(model.getDate()) + .setValue(model.getValue()) + .setCurrency(model.getCurrency()) + .setDescription(model.getDescription()) + .setFrom(model.getFrom()) + .setTo(model.getTo()) + .setLocation(model.getLocation()) + .setPayee(model.getPayee()) + .setIsPaidBack(model.getIsPaidBack()) + .buildSplitterEntry(); + + // Pass the new QuerySplitEntryData in the Gateway #insertSplitEntry. this.gateway.insertSplitEntry(User.getInstance().getCurrentBillID(), entry); } From 654ff4b882f3fc6d7e7715140c40ae57db0c6a3d Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Sat, 3 Dec 2022 01:47:41 -0500 Subject: [PATCH 3/6] [*] Modified BillUpdateUseCase to work with the new Database modification --- .../billgates/use_cases/bill_update/BillUpdateUseCase.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java b/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java index f009b01..1123434 100644 --- a/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java +++ b/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java @@ -40,8 +40,7 @@ public void updateBill(int billId) { } user.setCurrentBillID(billId); // get all entries of the current bill - List result = this.gateway.getBillData(user.getCurrentBillID()).getEntries() - .stream().map(d -> d.toEntryBuilder().buildEntry()).toList(); + List result = this.gateway.getBillData(user.getCurrentBillID()); List> list = result.stream().map(Entry::toObjects).toList(); // if the current bill id is not the same as the bill id, then the current bill is a splitter bill this.presenter.updateBill(new BillUpdateResponseModel(list, user.getCurrentBillID() != user.getBillId())); From 2407b65c1771f06c8893acb3721c501fa4cb6d7f Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Sat, 3 Dec 2022 02:00:08 -0500 Subject: [PATCH 4/6] [*] Modified Javadocs in the newly edited files --- src/main/java/billgates/entities/EntryBuilder.java | 2 +- src/main/java/billgates/entities/User.java | 3 ++- .../java/billgates/interface_adapters/DatabaseGateway.java | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/billgates/entities/EntryBuilder.java b/src/main/java/billgates/entities/EntryBuilder.java index b0de995..9eae2f6 100644 --- a/src/main/java/billgates/entities/EntryBuilder.java +++ b/src/main/java/billgates/entities/EntryBuilder.java @@ -6,8 +6,8 @@ /** * Clean Architecture Layer: Enterprise Business Rules * This is a builder class that help to build an Entry or Splitter Entry. - * This class implements a builder design pattern. *

+ * Design Pattern: Builder * The instance variables define the default values for each attribute. * Each setter method set an attribute of the entry and returns this EntryBuilder. * In this way, you can chain setters and build an Entry in one line. diff --git a/src/main/java/billgates/entities/User.java b/src/main/java/billgates/entities/User.java index 572c51b..34773ca 100644 --- a/src/main/java/billgates/entities/User.java +++ b/src/main/java/billgates/entities/User.java @@ -6,7 +6,8 @@ * Clean Architecture Layer: Enterprise Business Rules * This class represents a user entity in our program. * Only one user is allowed in the running time of our program. - * We implement the User using singleton design pattern. + *

+ * Design Pattern: Singleton * The UserJoinUseCase will initialize the user by calling getInstance(parameters). * Other use cases can use getInstance() (the one without parameters) to obtain the current user. * diff --git a/src/main/java/billgates/interface_adapters/DatabaseGateway.java b/src/main/java/billgates/interface_adapters/DatabaseGateway.java index 6ce5698..b81b03d 100644 --- a/src/main/java/billgates/interface_adapters/DatabaseGateway.java +++ b/src/main/java/billgates/interface_adapters/DatabaseGateway.java @@ -1,6 +1,5 @@ package billgates.interface_adapters; -import billgates.database.*; import billgates.entities.Entry; import billgates.entities.QueryUserData; import billgates.entities.SplitterEntry; @@ -10,6 +9,12 @@ /** * Clean Architecture Layer: Application Business Rules + * This class is being used by multiple use cases to retrieve, insert, and modify information + * that is used for the application. + *

+ * Design Pattern: Strategy + * We can implement the database gateway in multiple different types of databases + * The current implemented database by default, uses MySQL Database * * @author Ray, Scott */ From 13ec9f21d14fde2711e4b6b6ea6cbed7c6c7169b Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 3 Dec 2022 20:30:52 -0500 Subject: [PATCH 5/6] [*] Fixed a typing bug. --- .../billgates/use_cases/bill_update/BillUpdateUseCase.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java b/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java index bef6fab..8e20baa 100644 --- a/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java +++ b/src/main/java/billgates/use_cases/bill_update/BillUpdateUseCase.java @@ -1,7 +1,6 @@ package billgates.use_cases.bill_update; import billgates.entities.AbstractEntry; -import billgates.entities.Entry; import billgates.entities.User; import billgates.interface_adapters.DatabaseGateway; @@ -42,7 +41,7 @@ public void updateBill(int billId) { user.setCurrentBillID(billId); // we query the database asynchronously to make the program run smoother Thread thread = new Thread(() -> { - List result; + List result; if (user.getBillId() != user.getCurrentBillID()) { // if we are updating the splitter bill, then we create the splitter bill if // not exist From 2a3e2b5f7cda00b4d4b02a9b60645c7240975bf8 Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Sat, 3 Dec 2022 22:49:27 -0500 Subject: [PATCH 6/6] [*] Fixed formatting issues as requested by Scott --- src/main/java/billgates/entities/EntryBuilder.java | 2 +- src/main/java/billgates/entities/User.java | 2 +- src/main/java/billgates/interface_adapters/DatabaseGateway.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/billgates/entities/EntryBuilder.java b/src/main/java/billgates/entities/EntryBuilder.java index 9eae2f6..67b563e 100644 --- a/src/main/java/billgates/entities/EntryBuilder.java +++ b/src/main/java/billgates/entities/EntryBuilder.java @@ -5,9 +5,9 @@ /** * Clean Architecture Layer: Enterprise Business Rules + * Design Pattern: Builder * This is a builder class that help to build an Entry or Splitter Entry. *

- * Design Pattern: Builder * The instance variables define the default values for each attribute. * Each setter method set an attribute of the entry and returns this EntryBuilder. * In this way, you can chain setters and build an Entry in one line. diff --git a/src/main/java/billgates/entities/User.java b/src/main/java/billgates/entities/User.java index 34773ca..b551b09 100644 --- a/src/main/java/billgates/entities/User.java +++ b/src/main/java/billgates/entities/User.java @@ -4,10 +4,10 @@ /** * Clean Architecture Layer: Enterprise Business Rules + * Design Pattern: Singleton * This class represents a user entity in our program. * Only one user is allowed in the running time of our program. *

- * Design Pattern: Singleton * The UserJoinUseCase will initialize the user by calling getInstance(parameters). * Other use cases can use getInstance() (the one without parameters) to obtain the current user. * diff --git a/src/main/java/billgates/interface_adapters/DatabaseGateway.java b/src/main/java/billgates/interface_adapters/DatabaseGateway.java index b81b03d..f863b4d 100644 --- a/src/main/java/billgates/interface_adapters/DatabaseGateway.java +++ b/src/main/java/billgates/interface_adapters/DatabaseGateway.java @@ -9,10 +9,10 @@ /** * Clean Architecture Layer: Application Business Rules + * Design Pattern: Strategy * This class is being used by multiple use cases to retrieve, insert, and modify information * that is used for the application. *

- * Design Pattern: Strategy * We can implement the database gateway in multiple different types of databases * The current implemented database by default, uses MySQL Database *