Giter Club home page Giter Club logo

moneytransfer's Introduction

Transfer REST API

REST API that allows money transfer between accounts by using Vert.x .

Package and run with vertx-maven-plugin

$ mvn clean install -U -X vertx:run

Start application from command line via :

moneytransfer\target$ java -jar .\moneytransfer-0.0.1-SNAPSHOT.jar 
[vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Start setup initial database. [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Altered money_transfer table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Altered money_transfer table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Inserted sample row into the user table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Inserted sample row into the user table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Inserted sample row into the account table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Inserted sample row into the account table! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Created sample database schema! [vert.x-eventloop-thread-1] INFO c.company.moneytransfer.util.DBUtil - Sample DB rows populated for user and account tables!

NOT : If you receive "java.net.BindException" then find and kill the running process on port 9090 of WIN10 OS.
$ Failed to deploy : java.net.BindException: Address already in use: bind

$ netstat -nao | find "9090"
TCP    0.0.0.0:9090           0.0.0.0:0              LISTENING       9292
TCP    [::]:9090              [::]:0                 LISTENING       9292

$ taskkill /PID 9292 /F
SUCCESS: The process with PID 9292 has been terminated.

Tech Stack

Java 11
vertx-core
vertx-web
vertx-jdbc-client
vertx-unit
vertx-junit5
hsqldb
logback-classic
maven
vertx-maven-plugin

Database ER diagram :

er_diagram

Database Tables

CREATE TABLE user(id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY, name varchar(255));
CREATE TABLE account(id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY, userId integer NOT NULL, balance DECIMAL(10,2) NOT NULL );
CREATE TABLE money_transfer(id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY, fromAccountId integer NOT NULL, toAccountId integer NOT NULL, amount DECIMAL(10,2) NOT NULL, currency varchar(50) NOT NULL, transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
ALTER TABLE account ADD FOREIGN KEY(userId) REFERENCES user(id);
ALTER TABLE money_transfer ADD FOREIGN KEY(fromAccountId) REFERENCES account(id);
ALTER TABLE money_transfer ADD FOREIGN KEY(toAccountId) REFERENCES account(id);

Database Tables Definitions

user = Stores user details information
account = Stores accounts of users and balance information for each account
money_transfer = Join table for sender, receiver accounts and transfer amount with currency

Rest Api Design Decisions

  • When the Vert.x application starts in memory hsqldb is initialized and loaded with test data

  • Application can be started directly with the execution of main method inside the com.company.moneytransfer.AppMain class.

API OPERATIONS

Query users

Method : HTTP.GET
URL : http://localhost:9090/api/users

Input Test Data : No input just fire the request.

Request Body :

{
}

Curl Request :

curl --location --request GET 'http://localhost:9090/api/users' \
--header 'Content-Type: application/json' \
--data-raw '{
}'

Response :

HTTP response code 200

[
    {
        "ID": 1,
        "NAME": "user1"
    },
    {
        "ID": 2,
        "NAME": "user2"
    }
]

Query specific user by user id

Method : HTTP.GET
URL : http://localhost:9090/api/users/:id
URL : http://localhost:9090/api/users/1

Input Test Data : No input just fire the request. "id" field contains user information for the specific user.

Request Body :

{
}

Curl Request :

curl --location --request GET 'http://localhost:9090/api/users/1' \
--header 'Content-Type: application/json' \
--data-raw '{
}'

Response :

HTTP response code 200

{
    "ID": 1,
    "name": "user1"
}

Query accounts of specific user by user id

Method : HTTP.GET
URL : http://localhost:9090/api/accounts/:userid
URL : http://localhost:9090/api/accounts/1

Input Test Data : No input just fire the request. "userid" field contains user information for the specific user.

Request Body :

{
}

Curl Request :

curl --location --request GET 'http://localhost:9090/api/accounts/1' \
--header 'Content-Type: application/json' \
--data-raw '{
}'

Response :

HTTP response code 200

[
    {
        "ID": 1,
        "USERID": 1,
        "BALANCE": 100
    }
]

Accomplish transfer between accounts

Method : HTTP.POST
URL : http://localhost:9090/api/transfer

Input Test Data : Provide required fields for transfer operation.

Request Body :

{
	"fromAccountId": 1,
	"toAccountId": 2,
	"amount": 100,
	"currency": "GBP"
}

Curl Request :

curl --location --request POST 'http://localhost:9090/api/transfer' \
--header 'Content-Type: application/json' \
--data-raw '{
	"fromAccountId": 1,
	"toAccountId": 2,
	"amount": 100,
	"currency": "GBP"
}'

Response :

HTTP response code 200

{
    "transferResult": "Money transfer completed successfully!",
    "SenderAccountDetails": {
        "status": "ok",
        "id": 1,
        "userId": 1,
        "balance": 0.00
    },
    "ReceiverAccountDetails": {
        "status": "ok",
        "id": 2,
        "userId": 2,
        "balance": 300.00
    }
}

Query transfers made from given sender account id

Method : HTTP.GET
URL : http://localhost:9090/api/transfer/:accountid
URL : http://localhost:9090/api/transfer/1

Input Test Data : No input just fire the request. "accountid" field contains account information for the specific account.

Request Body :

{
}

Curl Request :

curl --location --request GET 'http://localhost:9090/api/transfer/1' \
--header 'Content-Type: application/json' \
--data-raw '{
}'

Response :

HTTP response code 200

[
    {
        "ID": 1,
        "FROMACCOUNTID": 1,
        "TOACCOUNTID": 2,
        "AMOUNT": 100.00,
        "CURRENCY": "GBP",
        "TRANSACTION_DATE": "2022-03-20T14:24:22.749"
    }
]

moneytransfer's People

Contributors

dependabot[bot] avatar tufangorel avatar

Watchers

 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.