Skip to content

Commit

Permalink
거래 금액에 대한 부호 표시 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gunkim committed May 20, 2024
1 parent e6f4aad commit d687952
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ private void runTransactions(AccountTransactionManager accountTransactionManager
}

private void printTransactions(AccountTransactionManager accountTransactionManager) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
final var formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");

System.out.printf("%-20s %-15s %-15s\n", "Date", "Amount", "Balance");
for (Transaction transaction : accountTransactionManager.findAll(FIXED_MY_ACCOUNT_ID)) {
System.out.printf("%-20s %-15s %-15s\n",
formatter.format(transaction.createdAt()),
transaction.amount(),
transaction.signedAmount(),
transaction.balance());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static Transaction of(AccountId accountId, TransactionType type, Money am
);
}

public String signedAmount() {
return type.prefix() + this.amount;
}

@Override
public int compareTo(Transaction transaction) {
return this.createdAt.compareTo(transaction.createdAt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package io.github.gunkim.banking.domain;

public enum TransactionType {
DEPOSIT, WITHDRAW
DEPOSIT("+"), WITHDRAW("-");

private final String prefix;

TransactionType(String prefix) {
this.prefix = prefix;
}

public String prefix() {
return prefix;
}
}

0 comments on commit d687952

Please sign in to comment.