diff --git a/src/main/java/ch/postfinance/swiss/hacks/domain/Transaction.java b/src/main/java/ch/postfinance/swiss/hacks/domain/Transaction.java index c55e998..902b0b5 100644 --- a/src/main/java/ch/postfinance/swiss/hacks/domain/Transaction.java +++ b/src/main/java/ch/postfinance/swiss/hacks/domain/Transaction.java @@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotNull; import java.math.BigDecimal; +import java.time.Instant; import java.util.UUID; @Entity @@ -33,4 +34,8 @@ public class Transaction extends PanacheEntity { @NotNull @Column(length = 22, nullable = false) public BigDecimal amount; + + @NotNull + @Column + public Instant persistedAt; } diff --git a/src/main/java/ch/postfinance/swiss/hacks/resource/AccountsResourceImpl.java b/src/main/java/ch/postfinance/swiss/hacks/resource/AccountsResourceImpl.java index 2a55618..3fd0891 100644 --- a/src/main/java/ch/postfinance/swiss/hacks/resource/AccountsResourceImpl.java +++ b/src/main/java/ch/postfinance/swiss/hacks/resource/AccountsResourceImpl.java @@ -9,10 +9,12 @@ import jakarta.ws.rs.PathParam; import jakarta.ws.rs.QueryParam; +import java.util.Comparator; import java.util.List; import static ch.postfinance.swiss.hacks.domain.Login.ROLE_ADMIN; import static ch.postfinance.swiss.hacks.domain.Login.ROLE_USER; +import static java.util.Comparator.comparing; @Authenticated public class AccountsResourceImpl implements AccountsResource { @@ -39,6 +41,7 @@ public List checkAccountBalance() { return accountService.currentUserAccounts() .map(accounts -> accounts.stream() .map(AccountsResourceImpl::convertToDTO) + .sorted(comparing(AccountBalance::getIban)) .toList()) .orElseThrow(); } diff --git a/src/main/java/ch/postfinance/swiss/hacks/resource/TransactionResourceImpl.java b/src/main/java/ch/postfinance/swiss/hacks/resource/TransactionResourceImpl.java index 7d67942..92667b7 100644 --- a/src/main/java/ch/postfinance/swiss/hacks/resource/TransactionResourceImpl.java +++ b/src/main/java/ch/postfinance/swiss/hacks/resource/TransactionResourceImpl.java @@ -12,11 +12,13 @@ import jakarta.ws.rs.BadRequestException; import org.slf4j.Logger; +import java.util.Date; import java.util.List; import static ch.postfinance.swiss.hacks.domain.Login.ROLE_ADMIN; import static ch.postfinance.swiss.hacks.domain.Login.ROLE_USER; import static ch.postfinance.swiss.hacks.resource.beans.TransferResponse.Status.SUCCESS; +import static java.util.Comparator.comparing; import static org.slf4j.LoggerFactory.getLogger; @Authenticated @@ -33,7 +35,8 @@ private static TransactionHistory convertToDTO(Transaction transaction) { transactionHistory.setFromIban(transaction.fromIban); transactionHistory.setToIban(transaction.toIban); transactionHistory.setAmount(transaction.amount.doubleValue()); - transactionHistory.setDescription(transactionHistory.getDescription()); + transactionHistory.setDescription(transaction.description); + transactionHistory.setPersistedAt(Date.from(transaction.persistedAt)); return transactionHistory; } @@ -65,6 +68,7 @@ public TransferResponse transferFunds(FundTransfer fundTransfer) { public List viewTransactionHistory() { return transactionService.getAllTransactions().stream() .map(TransactionResourceImpl::convertToDTO) + .sorted(comparing(TransactionHistory::getPersistedAt)) .toList(); } } diff --git a/src/main/resources/META-INF/resources/transactions/history.html b/src/main/resources/META-INF/resources/transactions/history.html index 47a7d3e..06970ae 100644 --- a/src/main/resources/META-INF/resources/transactions/history.html +++ b/src/main/resources/META-INF/resources/transactions/history.html @@ -35,6 +35,7 @@

Transaction History

From IBAN To IBAN Amount + Date @@ -62,7 +63,8 @@

Transaction History

${transaction.description ? transaction.description: ''} ${transaction.fromIban} ${transaction.toIban} - ${transaction.amount}`; + ${transaction.amount} + ${transaction.persistedAt}`; tableBody.appendChild(row); } }); diff --git a/src/main/resources/import.sql b/src/main/resources/import.sql index 4f4ee73..afcee57 100644 --- a/src/main/resources/import.sql +++ b/src/main/resources/import.sql @@ -8,13 +8,13 @@ VALUES ('CH9300762011623852957', 1234.56, 1001), ('CH5604835012345678009', 2345.67, 1001), ('CH1204835012345678009', 3456.78, 1002); -INSERT INTO Transaction (id, transactionId, description, fromIban, toIban, amount) -VALUES (1001, 'b1d025e0-77c8-422b-80a4-d59e4ef3e121', 'Payment for invoice #1234', 'CH9300762011623852957', 'CH1204835012345678009', 250.75), - (1002, '2782f1c9-3e2d-4a1b-a00c-d1f23b4f12ab', 'Salary for May', 'CH5604835012345678009', 'CH9300762011623852957', 3500.00), - (1003, '1e4f12a3-1e1e-4211-84b9-278e21cf432b', 'Refund for order #5678', 'CH1204835012345678009', 'CH9300762011623852957', 45.00), - (1004, '08b17a21-1f92-4412-a987-12b78e2f34aa', 'Payment for subscription', 'CH9300762011623852957', 'CH5604835012345678009', 15.99), - (1005, 'f23e1b42-9c12-4e0b-b872-a1c34df12e01', 'Transfer to savings', 'CH5604835012345678009', 'CH5604835012345678009', 1000.00), - (1006, 'a47c211e-b8f1-4123-9210-b34e12f3a09b', 'Gift to friend', 'CH1204835012345678009', 'CH5604835012345678009', 150.00); +INSERT INTO Transaction (id, transactionId, description, fromIban, toIban, amount, persistedAt) +VALUES (1001, 'b1d025e0-77c8-422b-80a4-d59e4ef3e121', 'Payment for invoice #1234', 'CH9300762011623852957', 'CH1204835012345678009', 250.75, '2024-06-27T10:15:30'), + (1002, '2782f1c9-3e2d-4a1b-a00c-d1f23b4f12ab', 'Salary for May', 'CH5604835012345678009', 'CH9300762011623852957', 3500.00, '2024-06-27T10:30:20'), + (1003, '1e4f12a3-1e1e-4211-84b9-278e21cf432b', 'Refund for order #5678', 'CH1204835012345678009', 'CH9300762011623852957', 45.00, '2024-06-28T05:30:15'), + (1004, '08b17a21-1f92-4412-a987-12b78e2f34aa', 'Payment for subscription', 'CH9300762011623852957', 'CH5604835012345678009', 15.99, '2024-06-28T10:15:30'), + (1005, 'f23e1b42-9c12-4e0b-b872-a1c34df12e01', 'Transfer to savings', 'CH5604835012345678009', 'CH5604835012345678009', 1000.00, '2024-06-29T14:45:35'), + (1006, 'a47c211e-b8f1-4123-9210-b34e12f3a09b', 'Gift to friend', 'CH1204835012345678009', 'CH5604835012345678009', 150.00, '2024-06-29T20:40:30'); INSERT INTO SupportContactInformation (id, email, phone) VALUES (1001, 'user1@example.com', '555-0101'), diff --git a/src/main/resources/openapi/openapi.yml b/src/main/resources/openapi/openapi.yml index a385739..c93f7bc 100644 --- a/src/main/resources/openapi/openapi.yml +++ b/src/main/resources/openapi/openapi.yml @@ -258,6 +258,9 @@ components: description: Must be a valid Swiss francs amount! description: type: string + persistedAt: + type: string + format: date-time PasswordChange: type: object required: