Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
}
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
implementation 'com.twilio.sdk:twilio:8.31.1'
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.core.dto;

import com.booleanuk.core.enums.AccountType;

public record CreateAccountRequestDto(int userId, AccountType accountType) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.booleanuk.core.dto;

public record CreateAccountResponseDto(boolean success, String message, int accountId, int userId, String accountType) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.core.dto;

import java.math.BigDecimal;

public record ReviewOverdraftResponseDto(boolean approved, String message, int accountId, BigDecimal amount) {
}
10 changes: 10 additions & 0 deletions src/main/java/com/booleanuk/core/dto/TransactionRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.booleanuk.core.dto;

import com.booleanuk.core.enums.AccountType;
import com.booleanuk.core.enums.TransactionType;

import java.math.BigDecimal;
import java.time.LocalDate;

public record TransactionRequestDto(int accountId, BigDecimal amount, TransactionType transactionType, LocalDate date) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core.dto;

import java.math.BigDecimal;
import java.time.LocalDate;

public record TransactionResponseDto(boolean success, String message, int accountId, String accountType, String transactionType, BigDecimal amount, LocalDate date, boolean overdraftRequest) {
}
6 changes: 6 additions & 0 deletions src/main/java/com/booleanuk/core/enums/AccountType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.core.enums;

public enum AccountType {
CURRENT,
SAVINGS
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/enums/TransactionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core.enums;

public enum TransactionType {
DEPOSIT,
WITHDRAW,
OVERDRAFT,
}
65 changes: 65 additions & 0 deletions src/main/java/com/booleanuk/core/model/BankAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.booleanuk.core.model;

import com.booleanuk.core.enums.AccountType;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class BankAccount {
private int id;
private AccountType accountType;
private BigDecimal balance; // not used since started working on extension
private int userId;
List<Transaction> transactions;

// Constructors
public BankAccount(int id, AccountType accountType, BigDecimal balance, int userId) {
this.id = id;
this.accountType = accountType;
this.balance = balance;
this.userId = userId;
transactions = new ArrayList<>();
}

// Getters & setters
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public AccountType getAccountType() {
return accountType;
}

public void setAccountType(AccountType accountType) {
this.accountType = accountType;
}

public BigDecimal getBalance() {
return balance;
}

public void setBalance(BigDecimal balance) {
this.balance = balance;
}

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public List<Transaction> getTransactions() {
return transactions;
}

public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/booleanuk/core/model/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.booleanuk.core.model;

public class Customer {
private int id;

// Constructors
public Customer(int id) {
this.id = id;
}

// Getters & setters
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/booleanuk/core/model/OverdraftRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.booleanuk.core.model;

import java.math.BigDecimal;

public class OverdraftRequest {
private int overdraftId;
private int accountId;
private BigDecimal amount;

public OverdraftRequest(int overdraftId, int accountId, BigDecimal amount) {
this.overdraftId = overdraftId;
this.accountId = accountId;
this.amount = amount;
}

public int getOverdraftId() {
return overdraftId;
}

public void setOverdraftId(int overdraftId) {
this.overdraftId = overdraftId;
}

public int getAccountId() {
return accountId;
}

public void setAccountId(int accountId) {
this.accountId = accountId;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}
}
54 changes: 54 additions & 0 deletions src/main/java/com/booleanuk/core/model/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.booleanuk.core.model;

import com.booleanuk.core.enums.TransactionType;

import java.math.BigDecimal;
import java.time.LocalDate;

public class Transaction {
private int id;
private BigDecimal amount;
private TransactionType transactionType;
private LocalDate date;

// Constructors
public Transaction(int id, BigDecimal amount, TransactionType transactionType, LocalDate date) {
this.id = id;
this.amount = amount;
this.transactionType = transactionType;
this.date = date;
}

// Getters and setters
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public TransactionType getTransactionType() {
return transactionType;
}

public void setTransactionType(TransactionType transactionType) {
this.transactionType = transactionType;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public LocalDate getDate() {
return date;
}

public void setDateTime(LocalDate date) {
this.date = date;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.booleanuk.core.repository;

import com.booleanuk.core.model.BankAccount;
import com.booleanuk.core.model.OverdraftRequest;
import com.booleanuk.core.model.Transaction;

import java.util.ArrayList;
import java.util.List;

public class BankAccountRepository implements IBankAccountRepository {
List<BankAccount> accounts;
List<OverdraftRequest> overdraftRequests;

// Constructors
public BankAccountRepository() {
this.accounts = new ArrayList<>();
this.overdraftRequests = new ArrayList<>();
}

// Methods
@Override
public void createAccount(BankAccount bankAccount) {

}

@Override
public void saveTransaction(int accountId, Transaction transaction) {

}

@Override
public BankAccount findBankAccountById(int accountId) {
return null;
}

@Override
public List<BankAccount> getAccounts() {
return accounts;
}

@Override
public List<OverdraftRequest> getOverdraftRequests() {
return List.of();
}

@Override
public OverdraftRequest getOverdraftRequestById(int overdraftId) {
return null;
}

@Override
public void addOverdraftRequest(OverdraftRequest overdraftRequest) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.booleanuk.core.repository;

import com.booleanuk.core.model.BankAccount;
import com.booleanuk.core.model.OverdraftRequest;
import com.booleanuk.core.model.Transaction;

import java.util.ArrayList;
import java.util.List;

public class BankAccountRepositoryStub implements IBankAccountRepository {
List<BankAccount> accounts;
List<OverdraftRequest> overdraftRequests; // Extensions

// Constructors
public BankAccountRepositoryStub() {
this.accounts = new ArrayList<>();
this.overdraftRequests = new ArrayList<>(); // Extensions
}

// Methods
@Override
public void createAccount(BankAccount bankAccount) {
accounts.add(bankAccount);
}

@Override
public void saveTransaction(int accountId, Transaction transaction) {
for (BankAccount account : accounts) {
if (account.getId() == accountId) {
account.getTransactions().add(transaction);
return;
}
}
throw new IllegalArgumentException("Account with ID " + accountId + " not found.");
}

@Override
public BankAccount findBankAccountById(int accountId) {
for (BankAccount account : accounts) {
if (account.getId() == accountId) {
return account;
}
}
throw new IllegalArgumentException("Account with ID " + accountId + " not found.");
}

@Override
public List<BankAccount> getAccounts() {
return accounts;
}

// Extensions
@Override
public List<OverdraftRequest> getOverdraftRequests() {
return overdraftRequests;
}

@Override
public OverdraftRequest getOverdraftRequestById(int overdraftId) {
for (OverdraftRequest request : overdraftRequests) {
if (request.getOverdraftId() == overdraftId) {
return request;
}
}
throw new IllegalArgumentException("Overdraft request with ID " + overdraftId + " not found.");
}

@Override
public void addOverdraftRequest(OverdraftRequest overdraftRequest) {
overdraftRequests.add(overdraftRequest);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.booleanuk.core.repository;

import com.booleanuk.core.model.BankAccount;
import com.booleanuk.core.model.OverdraftRequest;
import com.booleanuk.core.model.Transaction;

import java.util.List;

public interface IBankAccountRepository {
void createAccount(BankAccount bankAccount);
void saveTransaction(int accountId, Transaction transaction);
BankAccount findBankAccountById(int accountId);
List<BankAccount> getAccounts();
List<OverdraftRequest> getOverdraftRequests();
OverdraftRequest getOverdraftRequestById(int overdraftId);
void addOverdraftRequest(OverdraftRequest overdraftRequest);
}
Loading
Loading