Coder Social home page Coder Social logo

atm_machine's Introduction

ATM_Machine

Demo Java Application simulating ATM operations

Demo

Analytics DEmo

Installation

Clone the application:

git clone https://github.com/marcelus20/ATM_Machine

Build and Run Application using docker-compose

# Navigate to root folder
cd ATM_Machine
#run application
docker-compose up --build

Note If you need sudo to run docker, then you need to enter the following command instead:

# Navigate to root folder
cd ATM_Machine
#run application
sudo docker-compose up --build

When the above command completes and enviroments are up and running, you can access the ATM Analytics at localhost:3000 and Backend Rest at localhost:8080.

Usage

ATM Analytics

This is a simple frontend displaying the amount of bank notes remaining in the ATM machine. When the backend receives a withdraw command, the amount of bank notes should be updated on this dashboard.

Simply go to ATM Analytics at localhost:3000 and send some requests to the backend REST endpoints to see the amount of the remaining bank notes update in the screen.

ATM Backend Endpoints

For the sake of this assignment, this API allows you to only check balance, withdraw funds, authenticate and check status (how many notes remaining in the ATM machine).

Two test accounts have been hard-coded and data can be used to include in the requests:

  1. Account Number: 123456789 | PIN: 1234 | Initial Balance: 800 | Overdraft: 200
  2. Account Number: 987654321 | PIN: 4321 | Initial Balance: 1230 | Overdraft: 150

ATM will initialise with the following state:

  • A total funds of €1500 made up of different bank notes.
  • The amount for each bank note is 10 x €50s, 30 x €20s, 30 x €10s and 20 x €5s

Check the Status of the ATM (How Many Notes Remaining)

  • Endpoint: /status
  • method: GET
  • Example Request:
curl -X GET localhost:8080/status
  • Example Response:
{"fifties":10,"twenties":30,"tenners":30,"fivers":20,"total":1500.0}

Creating a session token

  • Endpoint: /session
  • method: POST
  • Expected Body Parameters accountNumber: Number|Long and pin: String
  • Example Request:
curl -H "Content-Type: application/json" \
-X POST http://localhost:8080/session \
-d '{"accountNumber":123456789,"pin":"1234"}'
  • Example Response:
{"accountId":123456789,"token":"kkISXzefRsfN","expires":1638611411706} #It lasts only one minute!
  • Error Messages:
    • accountNumber and pin parameters are required! accountNumber must be a Number Int or Long, whereas pin must be a String.
    • The account provided doesn't exist.
    • The PIN provided is incorrect.

Important!

Once you've obtained the the "token" response, you will need to set the header x-auth-token with this value, eg: "x-auth-token: kkISXzefRsfN", to interact with the /balance and /withdraw endpoints.


Check Account Balance

Note: You first need to create a session token to authenticate with the system. The token will expire one minute after it was created and you will need to create a new one if the current expires.

Assume that the generated session token and its value is kkISXzefRsfN, send the following params to the /balance endpoint:

  • Endpoint: /balance

  • method: GET

  • Expected Query Parameters accountNumber: Number|Long

  • Expected Headers: x-auth-token: String

  • Example Request

curl -X GET -G localhost:8080/balance -d accountNumber=123456789 -H "x-auth-token: kkISXzefRsfN"
  • Example Response
{"accountNumber":123456789,"accountBalance":800.0, "maximumWithdrawAmount":1000.0}
  • Error Messages:
    • Required request header 'x-auth-token' for method parameter type String is not present.
    • accountNumber parameter is required! accountNumber must be a Number, Int or Long.
    • The token provided is invalid.
    • The provided token has expired and thus cannot be used. You need to login again.

Perform Withdraw Request

Note: You first need to create a session token to authenticate with the system. The token will expire one minute after it was created and you will need to create a new one if the current expires.

Assume that the generated session token and its value is kkISXzefRsfN and you want to withdraw 150 of value, send the following json body data to the /withdraw endpoint:

  • Endpoint: /withdraw
  • method: POST
  • Expected Body accountNumber: Number|Long, token: String and value: Number|Integer
curl -H "Content-Type: application/json" \
-H "x-auth-token: iTZSkARSJjAY" \
-X POST http://localhost:8080/withdraw \
-d '{"accountNumber":123456789, "value": 150}'
  • Expected Response:
{"accountNumber":123456789,"balance":565.0,"withdraw":{"fifties":4,"twenties":1,"tenners":1,"fivers":1,"total":235}}
  • Error Messages:
    • Required request header 'x-auth-token' for method parameter type String is not present.
    • accountNumber, and value parameters are required! accountNumber must be a Number Int or Long, whereas token must be a String and value an Integer.
    • Insufficient Funds.
    • The value parameter must be a multiple of 50 or 20 or 10 or 5.
    • This request cannot be fulfilled because the ATM doesn't have enough cash.
    • The provided token has expired and thus cannot be used. You need to login again.
    • The token provided is invalid.

License

MIT

atm_machine's People

Contributors

marcelus20 avatar

Watchers

James Cloos avatar  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.