GithubHelp home page GithubHelp logo

kata-sg's Introduction

kata-SG

Bank account kata

Think of your personal bank account experience. When in doubt, go for the simplest solution.

Requirements

  • Deposit and Withdrawal
  • Account statement (date, amount, balance)
  • Statement printing

The expected result is a service API, and its underlying implementation, that meets the expressed needs.
Nothing more, especially no UI, no persistence.

User Stories

US 1:

In order to save money
As a bank client
I want to make a deposit in my account

US 2:

In order to retrieve some or all of my savings
As a bank client
I want to make a withdrawal from my account

US 3:

In order to check my operations
As a bank client
I want to see the history (operation, date, amount, balance) of my operations

Solution

Exposed REST API with the following endpoints

feature verb url request body response
Save/Withdraw POST /accounts/{accountId} { "amount": 10, "type": "SAVE" } {"result":"SUCCESSFUL","message":"Amount of 10$ successfully deposited in your account","balance":29}
Retrieve GET /accounts/{accountId} NA {"operations":[{"type":"SAVE","amount":10,"balance":10,"date":"2023-06-12"},{"type":"WITHDRAW","amount":1,"balance":9,"date":"2023-06-14"}]}

Examples

View account history

curl http://localhost:8080/bank-service/api/v1/accounts/ACCOUNT_001
{
  "operations": [
    {
      "type": "SAVE",
      "amount": 10,
      "balance": 10,
      "date": "2023-06-12"
    },
    {
      "type": "WITHDRAW",
      "amount": 1,
      "balance": 9,
      "date": "2023-06-14"
    },
    {
      "type": "SAVE",
      "amount": 10,
      "balance": 19,
      "date": "2023-06-15"
    },
    {
      "type": "SAVE",
      "amount": 10,
      "balance": 29,
      "date": "2023-06-15"
    }
  ]
}

Successful money deposit

curl -X POST \
     -H "Content-Type: application/json" \
     -d '{ "amount": 10, "type": "SAVE" }' \
     http://localhost:8080/bank-service/api/v1/accounts/ACCOUNT_001
{
  "result":"SUCCESSFUL",
  "message":"Amount of 10$ successfully deposited in your account",
  "balance":19
}

Successful money withdrawal

curl -X POST \
     -H "Content-Type: application/json" \
     -d '{ "amount": 10, "type": "WITHDRAW" }' \
     http://localhost:8080/bank-service/api/v1/accounts/ACCOUNT_001
{
  "result":"SUCCESSFUL",
  "message":"Amount of 10$ withdrawn from your account",
  "balance":9
}

Insufficient account balance

curl -X POST \
     -H "Content-Type: application/json" \
     -d '{ "amount": 100, "type": "WITHDRAW" }' \
     http://localhost:8080/bank-service/api/v1/accounts/ACCOUNT_001
{
  "result":"FAILED",
  "message":"Insufficient account balance",
  "balance":19
}

TODO

  • add the case where the account did not exist
  • add exception management
  • add logging
  • add support for swagger
  • add persistence
  • add unit tests for the controller
  • add BDD test

kata-sg's People

Contributors

aymenmarouani 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.