diff --git a/src/main/java/nl/utwente/ing/controller/BalanceHistoryController.java b/src/main/java/nl/utwente/ing/controller/BalanceHistoryController.java index d78d5c1..7f8ba86 100644 --- a/src/main/java/nl/utwente/ing/controller/BalanceHistoryController.java +++ b/src/main/java/nl/utwente/ing/controller/BalanceHistoryController.java @@ -147,7 +147,7 @@ public String getBalanceHistory(@RequestHeader(value = "X-session-ID", required List historyItems = new LinkedList<>(); // Create an initial HistoryItem with the balance of the account as values. - HistoryItem currentItem = new HistoryItem(sum); + HistoryItem currentItem = new HistoryItem(sum, calendar.getTimeInMillis() / 1000); historyItems.add(currentItem); int groupCount = 0; @@ -155,7 +155,8 @@ public String getBalanceHistory(@RequestHeader(value = "X-session-ID", required // In case there are no transactions, fill the results with groups representing the sum and no movement. if (transactionsSet.isAfterLast()) { while (historyItems.size() < count) { - historyItems.add(new HistoryItem(sum)); + calendar.add(intervalType, -1); + historyItems.add(new HistoryItem(sum, calendar.getTimeInMillis() / 1000)); } } @@ -165,9 +166,9 @@ public String getBalanceHistory(@RequestHeader(value = "X-session-ID", required pointer.setTime(DATE_FORMAT.parse(transactionsSet.getString("date"))); while (calendar.after(pointer)) { - currentItem = new HistoryItem(currentItem.getOpen()); - historyItems.add(currentItem); calendar.add(intervalType, -1); + currentItem = new HistoryItem(currentItem.getOpen(), calendar.getTimeInMillis() / 1000); + historyItems.add(currentItem); } long amount = transactionsSet.getLong("amount"); @@ -186,9 +187,9 @@ public String getBalanceHistory(@RequestHeader(value = "X-session-ID", required } // Some data from the old group has to be carried over to the new group. - currentItem = new HistoryItem(currentItem.getOpen()); - historyItems.add(currentItem); calendar.add(intervalType, -1); + currentItem = new HistoryItem(currentItem.getOpen(), calendar.getTimeInMillis() / 1000); + historyItems.add(currentItem); } // Update the open value, which is the "current" value. @@ -208,7 +209,8 @@ public String getBalanceHistory(@RequestHeader(value = "X-session-ID", required // In case not enough transactions were retrieved from the database to fill the count: // Similarly to the case of the empty set, create items of the last sum without any movement. while (historyItems.size() < count) { - historyItems.add(new HistoryItem(endSum)); + calendar.add(intervalType, -1); + historyItems.add(new HistoryItem(endSum, calendar.getTimeInMillis() / 1000)); } GsonBuilder gsonBuilder = new GsonBuilder(); @@ -238,6 +240,7 @@ public JsonElement serialize(HistoryItem historyItem, Type type, JsonSerializati object.addProperty("high", historyItem.getHigh() / 100.0); object.addProperty("low", historyItem.getLow() / 100.0); object.addProperty("volume", historyItem.getVolume() / 100.0); + object.addProperty("timestamp", historyItem.getTimestamp()); return object; } } diff --git a/src/main/java/nl/utwente/ing/model/HistoryItem.java b/src/main/java/nl/utwente/ing/model/HistoryItem.java index d32e516..853d753 100644 --- a/src/main/java/nl/utwente/ing/model/HistoryItem.java +++ b/src/main/java/nl/utwente/ing/model/HistoryItem.java @@ -30,12 +30,14 @@ public class HistoryItem { private long high; private long low; private long volume; + private long timestamp; - public HistoryItem(long start) { + public HistoryItem(long start, long timestamp) { this.open = start; this.close = start; this.high = start; this.low = start; + this.timestamp = timestamp; } public long getOpen() { @@ -73,4 +75,8 @@ public long getVolume() { public void setVolume(long volume) { this.volume = volume; } + + public long getTimestamp() { + return timestamp; + } }