Coder Social home page Coder Social logo

chuyennm / virtual-wallet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saurabhsingh13no/virtual-wallet

0.0 0.0 0.0 65 KB

Building a Java library for online banking platform to build the virtual wallet to track users transaction account.

Java 99.70% HTML 0.30%

virtual-wallet's Introduction

About

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.

Problem Statement

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.

UML Diagram

Following UML diagram indicates the database tables and thier interaction which I am using.

UML-2

How to run the project

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

landing-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

Functionality

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 :

sample-data2

  • You can see the entries in the table for yourself. Navigate to http://localhost:8080/h2-console .You would see below screen :

H2-starting-session

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 :

  • a) Add an account to user 4 (Dan in this case) :

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:

add-Account

  • b) Create a new wallet for a user :

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 :

create-wallet

You can now check, that wallet 4 is now associated with user 4 :

create-Wallet

  • c) Return current account balance :

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 :

check-balance

The backend JAVA code checks for all validation. If the accountId is not associated with provided walledId, an exception is thrown.

  • d) Perform a withdrawal transaction on an account :

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 :

withdraw

We can now check that $100 was actually withdrawn from the account as is reflected in the database :

after-withdraw

  • e) Perform a deposit transaction on an account :

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 :

deposit

We can now check that account 1000 does have a new deposit of $200 by running select query on table account :

after-deposit

  • f) Perform a transfer from one account to another 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 :

transfer

Let us confirm the transfer by checking in the database :

after-transfer-again

  • g) Return last N transactions for an account :

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 :

last-NTransations

virtual-wallet's People

Contributors

saurabhsingh13no avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.