Git Product home page Git Product logo

bank_api's Introduction

Bank API

Set up

Docker (recommended)

If you are on Linux, install docker for Linux:

If you are on MacOS, install Docker-Compose, VirtualBox, docker-machine and NFS.

Building the project

  1. Give execute permissions to the start script: chmod +x script/start.sh (from the project's root)
  2. Run docker-compose build
  3. Once the project is built, run docker-compose up
  4. Once it finishes compiling and bringing the app up, you should be able to access the app on:
  • Run: docker-machine ip
  • You should be able to access the app by routing to the docker-machine ip printed from the command above. For example, http://192.168.99.100:4000.
  • Or you might have already mapped this locally to localhost or dev. For example, http://localhost:4000 or http://dev:4000.

Locally

You will need to have all these dependencies installed (You may want to follow the installation guide on https://hexdocs.pm/phoenix/installation.html):

  • Elixir installed
  • Mix installed
  • Phoenix Framework
  • Postgres

Once you have installed it, you should:

  1. Give permission to the script to execute chmod +x script/start.sh.
  2. Run the script ./script/start.sh

Seeding data

When you run docker-compose up or ./script/start.sh a script on /priv/repo/seeds.exs will run and initially populate the database.

Bank API

The solution proposed to the exercise is to create a checking_accounts table. That is associated with a transactions table, this table persists the operations made by the credit and debit operations.

Operations API

Credit

Creates a credit transaction to the users account

POST /api/v1/checking_account/:checking_account_id/credit/:amount

Parameters

  • checking_account_id (Integer) - Users account id
  • amount (Float) - Amount to credit
  • description (string) - Description of transaction
  • date (UTC Timestamp) - Amount to credit

Status

  • 200
  • 404
  • 400

Example

POST /api/v1/checking_account/1/credit/100.0?description=payment+from+jow&date=1503704316

{
  "data": "success"
}

Debit

Creates a debit (negative amount) transaction to the users account.

POST /api/v1/checking_account/:checking_account_id/debit/:amount

Parameters

  • checking_account_id (Integer) - Users account id
  • amount (Float) - Amount to credit
  • description (string) - Description of transaction
  • date (UTC Timestamp) - Amount to credit

Status

  • 200
  • 404
  • 400

Example

POST /api/v1/checking_account/1/credit/100.0?description=buy+book&date=1503704316

{
  "data": "success"
}

Balance

Returns the sum of amount over all transactions created for this user

GET /api/v1/checking_account/:checking_account_id/balance

Parameters

  • checking_account_id (Integer) - Users account id

Status

  • 200
  • 404

Example

GET /api/v1/checking_account/1/balance

{
  "data": {
    "balance": 123.0
  }
}

Bank Statement

Returns the bank statement regarding the given checking account. Given optional start and end date. If start_date and end_date are not given, statement for all transactions will return.

GET /api/v1/checking_account/:checking_account_id/statement

Parameters

  • checking_account_id (Integer) - Users account id
  • start_date (UTC Timestamp or YYYY-MM-DD) - start date of the statement
  • end_date (UTC Timestamp or YYYY-MM-DD) - end date of the statement

Status

  • 200
  • 404
  • 400

Example

GET /api/v1/checking_account/1/statement

{
  "data": [
    {
      "balance": 123.0,
      "date": "2017-08-25",
      "transactions": [
        {
          "description": "a description",
          "amount" : "1204",
          "ts" : 1234556
        },
        {
          "description": "Another description",
          "amount" : "-14.0",
          "ts" : 1234523
        }
      ]
    }
  ]
}

Periods of Debt

Returns all the periods in which the given user was on debt.

GET /api/v1/checking_account/:checking_account_id/periods_of_debt

Parameters

  • checking_account_id (Integer) - Users account id

Status

  • 200
  • 404

Example

GET /api/v1/checking_account/1/periods_of_debt

{
  "data": [
    {
      "start": "2017-08-01",
      "end": "2017-08-04",
      "principal" : "120.0"
    },
    {
      "start": "2017-08-20",
      "end": null,
      "principal" : "120.0"
    }
  ]
}

bank_api's People

Contributors

luizparreira avatar

Watchers

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