Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix: sortings on API
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Jun 29, 2024
1 parent 4d42623 commit 682894c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.validation.constraints.NotNull;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.UUID;

@Entity
Expand All @@ -33,4 +34,8 @@ public class Transaction extends PanacheEntity {
@NotNull
@Column(length = 22, nullable = false)
public BigDecimal amount;

@NotNull
@Column
public Instant persistedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,6 +41,7 @@ public List<AccountBalance> checkAccountBalance() {
return accountService.currentUserAccounts()
.map(accounts -> accounts.stream()
.map(AccountsResourceImpl::convertToDTO)
.sorted(comparing(AccountBalance::getIban))
.toList())
.orElseThrow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -65,6 +68,7 @@ public TransferResponse transferFunds(FundTransfer fundTransfer) {
public List<TransactionHistory> viewTransactionHistory() {
return transactionService.getAllTransactions().stream()
.map(TransactionResourceImpl::convertToDTO)
.sorted(comparing(TransactionHistory::getPersistedAt))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h1>Transaction History</h1>
<th>From IBAN</th>
<th>To IBAN</th>
<th>Amount</th>
<th>Date</th>
</tr>
</thead>
<tbody id="transactionHistoryBody">
Expand Down Expand Up @@ -62,7 +63,8 @@ <h1>Transaction History</h1>
<td>${transaction.description ? transaction.description: ''}</td>
<td>${transaction.fromIban}</td>
<td>${transaction.toIban}</td>
<td>${transaction.amount}</td>`;
<td>${transaction.amount}</td>
<td>${transaction.persistedAt}</td>`;
tableBody.appendChild(row);
}
});
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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, '[email protected]', '555-0101'),
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 682894c

Please sign in to comment.