Skip to content

Commit

Permalink
Merge pull request #116 from CSC207-2022F-UofT/ray
Browse files Browse the repository at this point in the history
[*] Removed warning of duplicated lines in IntelliJ
  • Loading branch information
ScottCTD authored Dec 8, 2022
2 parents f0e624e + 4dc0f96 commit 45c88c7
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/main/java/billgates/database/MySQLDatabaseGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ WHERE date BETWEEN CAST('%s' AS DATETIME) AND CAST('%s' AS DATETIME)
return entries;
}

// This is a method specifically used to obtain:
// Value, time, currency, description, from, to, location
public List<Object> getBasicEntryInfo(ResultSet resultSet) throws SQLException {
double value = resultSet.getDouble("value");
Timestamp date = resultSet.getTimestamp("date");
String currency = resultSet.getString("currency");
String description = resultSet.getString("description");
String from = resultSet.getString("from");
String to = resultSet.getString("to");
String location = resultSet.getString("location");

return new ArrayList<>(List.of(value,
date,
currency,
description,
from,
to,
location));
}

@Override
public Entry getEntryData(int billId, int entryId) {
int splitBillId;
Expand All @@ -221,15 +241,19 @@ public Entry getEntryData(int billId, int entryId) {
if (resultSet.next()) {
// Note that, aside from the general types that we have here
// All the rest objects will be parsed in a string format
value = resultSet.getDouble("value");
Timestamp date = resultSet.getTimestamp("date");
currency = resultSet.getString("currency");
description = resultSet.getString("description");
from = resultSet.getString("from");
to = resultSet.getString("to");
location = resultSet.getString("location");

splitBillId = resultSet.getInt("split_bill_id");

List<Object> result = getBasicEntryInfo(resultSet);

value = (double) result.get(0);
Timestamp date = (Timestamp) result.get(1);
currency = (String) result.get(2);
description = (String) result.get(3);
from = (String) result.get(4);
to = (String) result.get(5);
location = (String) result.get(6);

Instant i = Instant.ofEpochMilli(date.getTime());

// We can pass in the different zones we want to convert in,
Expand Down Expand Up @@ -283,6 +307,7 @@ public SplitterEntry getSplitEntryData(int billId, int entryId) {
if (resultSet.next()) {
// Note that, aside from the general types that we have here
// All the rest objects will be parsed in a string format

value = resultSet.getDouble("value");
Timestamp date = resultSet.getTimestamp("date");
currency = resultSet.getString("currency");
Expand Down

0 comments on commit 45c88c7

Please sign in to comment.