This project is about Building a Java library for online banking platform to build the virtual wallet to track users transaction account.
This is a spring boot application with in memory database H2. I am using JPA(Java Persistance API) to interact with the in memory database.
Infiniti Space Bank is launching a brand new online banking platform and they want us to build a Java library to build the virtual wallet to track users transaction account. https://en.wikipedia.org/wiki/Transaction_account . At a high level the library needs to solve the following business needs
- Track a user’s account balance
- Manage account transactions in the form of debits (withdrawals) and credits (deposits).
- Allow a user to transfer money to another user/account.
- Keep a history of last N transactions.
Following UML diagram indicates the database tables and thier interaction which I am using.
Following steps illustrate procedures you need to follow to run the code :
Step 1
: Download the repository
$ git clone https://github.com/saurabhsingh13no/virtual-wallet.git
$ cd virtual-wallet
Step 2
: Build the project using maven
$ mvn clean install
Step 3
: run the project
$ mvn spring-boot:run
- Now navigate to http://localhost:8080/ . You would see something like below index.html page :
Congratulations. You have successfully cloned the repo.
- Note : If you want to check the test coverage, open the project in IntelliJ and right click on project and click run with coverage>All tests
Since project uses H2 in-memory database, some sample data has already been provided to get started with. Below are snapshot of data that already exists in the table :
- You can see the entries in the table for yourself. Navigate to
http://localhost:8080/h2-console
.You would see below screen :
Make sure that you use jdbc:h2:mem:testdb
as JDBC URL. Click connect.
Enter below select queries to see the output :
select * from customer;
select * from wallet;
select * from account;
select * from bank_transaction;
Press ctrl+enter
.
Now, I think you are all set up. Lets see what this library can do :
Provided endpoint : http://localhost:8080/api/account/
use post request as :
{
"balance":4000,
"accountHolder" : {
"userId": 4,
"fname" : "Dan",
"lname":"Brown",
"email" :"dan@brown"
}
}
We can now check that Account 3001 is now associated with userId 4 and no wallet:
I am assuming a user can have multiple accounts.
Provided endpoint for creating new wallet :
http://localhost:8080/api/wallet/{customerId}
I used Postman
for this, since it provides easy interface for sending post request.
e.g. Lets create a wallet for ** Dan Brown** our 4th user in the database. We would post request to http://localhost:8080/api/wallet/4
using below JSON format :
You can now check, that wallet 4 is now associated with user 4 :
Provided endpoint : http://localhost:8080/api/wallet/{walletId}/account/{accountId}/balance
.
e.g Let us check balance for User 1 and associated account number 1000. We would use a GET request to http://localhost:8080/api/wallet/1/account/1000/balance
. Below is the output from postman :
The backend JAVA code checks for all validation. If the accountId is not associated with provided walledId, an exception is thrown.
Provided endpoint : http://localhost:8080/api/wallet/{walletId}/account/{accountId}/withdraw/{amount}
Allows one to withdraw amount from account associated with wallet.
e.g. Lets withdraw $100 from accountId 1000 associated with walletId 1. I use POST request to http://localhost:8080/api/wallet/1/account/1000/withdraw/100
in Postman. Following is the output :
We can now check that $100 was actually withdrawn from the account as is reflected in the database :
Provided endpoint : http://localhost:8080/api/wallet/{walletId}/account/{accountId}/deposit/{amount}
Allows one to deposit amount into an account associated with a wallet.
e.g. Lets deposit $200 to accountId 1000 associated with walletId 1. I use POST request to http://localhost:8080/api/wallet/1/account/1000/deposit/200
in Postman. Following is the output :
We can now check that account 1000 does have a new deposit of $200 by running select query on table account :
Provided endpoint :
http://localhost:8080/api/wallet/{walletId}/account/{trasferFromAccountId}/transfer/wallet/{toWalletId}/account/{transferToAccountId}/amount/{amount}
.
Allows one to transfer money from one account in one wallet to another account in another wallet.
e.g. Let us transfer $150 from accountId 1000 associated with walletId 1 to accountId 2000 associated with wallet 2 . I use a POST request to http://localhost:8080/api/wallet/1/account/1000/transfer/wallet/2/account/2000/amount/150
in Postman. Following is the output :
Let us confirm the transfer by checking in the database :
Provided endpoint : http://localhost:8080/api/wallet/{walletId}/account/{accountId}/lastNTransactions/{n}
.
Allows one to check their respect transaction statement.
e.g. Let us check for last 3 transactions for accountId 1000 associated with walletId 1. I use a GET request to http://localhost:8080/api/wallet/1/account/1000/lastNTransactions/3
in Postman. Following is the output :