Refactored models, preparing for immutable model records.

This commit is contained in:
Andrew Lalis 2024-01-01 21:30:55 -05:00
parent 63bb7cb097
commit be8e5dd3ca
7 changed files with 28 additions and 60 deletions

View File

@ -8,9 +8,9 @@ import java.util.Currency;
* credit-card, etc.). * credit-card, etc.).
*/ */
public class Account { public class Account {
private long id; private final long id;
private LocalDateTime createdAt; private final LocalDateTime createdAt;
private boolean archived; private final boolean archived;
private AccountType type; private AccountType type;
private String accountNumber; private String accountNumber;
@ -27,14 +27,6 @@ public class Account {
this.currency = currency; this.currency = currency;
} }
public Account(AccountType type, String accountNumber, String name, Currency currency) {
this.archived = false;
this.type = type;
this.accountNumber = accountNumber;
this.name = name;
this.currency = currency;
}
public AccountType getType() { public AccountType getType() {
return type; return type;
} }

View File

@ -36,13 +36,13 @@ public class AccountEntry {
DEBIT DEBIT
} }
private long id; private final long id;
private LocalDateTime timestamp; private final LocalDateTime timestamp;
private long accountId; private final long accountId;
private long transactionId; private final long transactionId;
private BigDecimal amount; private final BigDecimal amount;
private Type type; private final Type type;
private Currency currency; private final Currency currency;
public AccountEntry(long id, LocalDateTime timestamp, long accountId, long transactionId, BigDecimal amount, Type type, Currency currency) { public AccountEntry(long id, LocalDateTime timestamp, long accountId, long transactionId, BigDecimal amount, Type type, Currency currency) {
this.id = id; this.id = id;
@ -54,14 +54,6 @@ public class AccountEntry {
this.currency = currency; this.currency = currency;
} }
public AccountEntry(long accountId, long transactionId, BigDecimal amount, Type type, Currency currency) {
this.accountId = accountId;
this.transactionId = transactionId;
this.amount = amount;
this.type = type;
this.currency = currency;
}
public long getId() { public long getId() {
return id; return id;
} }

View File

@ -1,5 +1,8 @@
package com.andrewlalis.perfin.model; package com.andrewlalis.perfin.model;
/**
* Represents the different possible account types in Perfin.
*/
public enum AccountType { public enum AccountType {
CHECKING("Checking"), CHECKING("Checking"),
SAVINGS("Savings"), SAVINGS("Savings"),

View File

@ -12,11 +12,11 @@ import java.time.format.DateTimeFormatter;
* account balance record. * account balance record.
*/ */
public class Attachment { public class Attachment {
private long id; private final long id;
private LocalDateTime timestamp; private final LocalDateTime timestamp;
private String identifier; private final String identifier;
private String filename; private final String filename;
private String contentType; private final String contentType;
public Attachment(long id, LocalDateTime timestamp, String identifier, String filename, String contentType) { public Attachment(long id, LocalDateTime timestamp, String identifier, String filename, String contentType) {
this.id = id; this.id = id;
@ -26,13 +26,6 @@ public class Attachment {
this.contentType = contentType; this.contentType = contentType;
} }
public Attachment(LocalDateTime timestamp, String identifier, String filename, String contentType) {
this.timestamp = timestamp;
this.identifier = identifier;
this.filename = filename;
this.contentType = contentType;
}
public long getId() { public long getId() {
return id; return id;
} }

View File

@ -10,12 +10,12 @@ import java.util.Currency;
* correct balance. * correct balance.
*/ */
public class BalanceRecord { public class BalanceRecord {
private long id; private final long id;
private LocalDateTime timestamp; private final LocalDateTime timestamp;
private long accountId; private final long accountId;
private BigDecimal balance; private final BigDecimal balance;
private Currency currency; private final Currency currency;
public BalanceRecord(long id, LocalDateTime timestamp, long accountId, BigDecimal balance, Currency currency) { public BalanceRecord(long id, LocalDateTime timestamp, long accountId, BigDecimal balance, Currency currency) {
this.id = id; this.id = id;
@ -25,12 +25,6 @@ public class BalanceRecord {
this.currency = currency; this.currency = currency;
} }
public BalanceRecord(long accountId, BigDecimal balance, Currency currency) {
this.accountId = accountId;
this.balance = balance;
this.currency = currency;
}
public long getId() { public long getId() {
return id; return id;
} }

View File

@ -16,7 +16,7 @@ public class Transaction {
private final BigDecimal amount; private final BigDecimal amount;
private final Currency currency; private final Currency currency;
private String description; private final String description;
public Transaction(long id, LocalDateTime timestamp, BigDecimal amount, Currency currency, String description) { public Transaction(long id, LocalDateTime timestamp, BigDecimal amount, Currency currency, String description) {
this.id = id; this.id = id;

View File

@ -9,10 +9,10 @@ import java.time.LocalDateTime;
* record, or modifications to the account's properties. * record, or modifications to the account's properties.
*/ */
public class AccountHistoryItem { public class AccountHistoryItem {
private long id; private final long id;
private LocalDateTime timestamp; private final LocalDateTime timestamp;
private long accountId; private final long accountId;
private AccountHistoryItemType type; private final AccountHistoryItemType type;
public AccountHistoryItem(long id, LocalDateTime timestamp, long accountId, AccountHistoryItemType type) { public AccountHistoryItem(long id, LocalDateTime timestamp, long accountId, AccountHistoryItemType type) {
this.id = id; this.id = id;
@ -21,12 +21,6 @@ public class AccountHistoryItem {
this.type = type; this.type = type;
} }
public AccountHistoryItem(LocalDateTime timestamp, long accountId, AccountHistoryItemType type) {
this.timestamp = timestamp;
this.accountId = accountId;
this.type = type;
}
public long getId() { public long getId() {
return id; return id;
} }