-
Notifications
You must be signed in to change notification settings - Fork 24
feat: implement bank account system with audit logging to BankATM #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0ac1a4
feat: implement bank account system with audit logging and adds a sav…
Dlafferty251 0e88098
feat: integrate Log4j for enhanced audit logging functionality
Dlafferty251 c2e71de
refactor: simplify BankAccount and update SavingsAccount to abstract …
Dlafferty251 a76da9d
Fix: Do not need implementation for log4j
Dlafferty251 1f7dae4
feat: enhance AuditLog with log entry tracking and add unit tests
Dlafferty251 36f06a1
feat: implement SavingsAccount class with overridden methods and add …
Dlafferty251 c36cc92
Feat: Adds more auditLogging features in BankATM
Dlafferty251 4d25713
Chore: Adds JavaDoc to AuditLog and SavingsAccount
Dlafferty251 387c5e1
Feat: Enhance withdrawal to not allow checks to be written from savin…
Dlafferty251 b9c341d
Fix: Allows Checks to pass on github
Dlafferty251 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/AuditLog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
|
||
import java.util.ArrayList; | ||
|
||
public class AuditLog { | ||
private List<String> logEntries = new ArrayList<>(); | ||
|
||
public void log (String message) { | ||
logEntries.add(message); | ||
System.out.println(message); | ||
|
||
} | ||
|
||
public List<String> getEntries() { | ||
return logEntries; | ||
} | ||
|
||
public void clear() { | ||
logEntries.clear(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BankAccount.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.codedifferently.lesson17.bank; | ||
/* We want to support a Savings Account that works just like CheckinAccount, | ||
* But will not allow you to write checks aainst the account. | ||
* | ||
* We want the BankAtm class to support the concept of a Business Checking Account | ||
* A business acount will require that at least ne of the owning accoutns is a business account. | ||
* | ||
*/ | ||
|
||
public abstract class BankAccount { | ||
protected String accountNumber; | ||
protected double balance; | ||
|
||
public abstract void deposit(double amount, String method); | ||
public abstract void withdraw(double amount); | ||
|
||
public double getBalance() { | ||
return balance; | ||
} | ||
public String getAccountNumber() { | ||
return accountNumber; | ||
} | ||
|
||
//Follows LSP | ||
public interface depositable { | ||
Dlafferty251 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void deposit(double amount, String method); | ||
} | ||
public interface withdrawable { | ||
void withdraw(double amount); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException; | ||
|
||
/** Represents a bank ATM. */ | ||
public class BankAtm { | ||
|
||
private final Map<UUID, Customer> customerById = new HashMap<>(); | ||
private final Map<String, CheckingAccount> accountByNumber = new HashMap<>(); | ||
|
||
private final AuditLog auditLog = new AuditLog(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Violates the D in SOLID, no? |
||
/** | ||
* Adds a checking account to the bank. | ||
* | ||
|
@@ -48,6 +49,7 @@ public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) { | |
public void depositFunds(String accountNumber, double amount) { | ||
CheckingAccount account = getAccountOrThrow(accountNumber); | ||
account.deposit(amount); | ||
auditLog.log("Deposited " + amount + " into account " + accountNumber); | ||
} | ||
|
||
/** | ||
|
@@ -58,8 +60,11 @@ public void depositFunds(String accountNumber, double amount) { | |
*/ | ||
public void depositFunds(String accountNumber, Check check) { | ||
CheckingAccount account = getAccountOrThrow(accountNumber); | ||
|
||
check.depositFunds(account); | ||
} | ||
auditLog.log("Deposited check into account " + accountNumber); | ||
|
||
} | ||
|
||
/** | ||
* Withdraws funds from an account. | ||
|
18 changes: 18 additions & 0 deletions
18
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/SavingsAccount.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//Only Allows Deposits when accessing Atm on your Savings Account | ||
|
||
public class SavingsAccount extends BankAccount { | ||
|
||
@Override | ||
public void deposit(double amount, String method) { | ||
if("check".equalsIgnoreCase(method)) { | ||
throw new UnsupportedOperationException("Deposit not allowed"); | ||
} | ||
|
||
this.balance += amount; | ||
} | ||
|
||
@Override | ||
public void withdraw(double amount) { | ||
throw new IllegalArgumentException("Insufficient funds"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bad implementation, good work. You might be interested in a library called
Log4j
that could be useful to you as well, but this is good enough for your homework.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored AuditLog class to Implement Log4j logic instead of custom implementation.