Git Product home page Git Product logo

banking-api's Introduction

Code Challenge: Go(lang)

Goal of this project

The goal of this project is provide a transfer API between internal accounts of a digital bank.

Requirements

Run Application

make build
make run

Run Tests

make test

Routes:

Create an account:

  • Method: POST

  • URL: /accounts

  • Body:

    {
      "name": "account-test",
      "cpf": "97014963023",
      "secret": "u69UFv$*ETH4",
      "balance": 100
    }
  • Responses:

    • Success:
      • Status code: 201 - Created
      • Example body:
      {
        "account_id": 53
      }
    • Errors:
      • Request with invalid syntax
        • Status code: 400 - Bad Request
        • Example body:
        {
          "error": "secret must be at least 8 characters long"
        }
      • Request with CPF already registered
        • Status code: 409 - Conflict
        • Example body:
        {
          "error": "CPF already exists"
        }
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Get account list:

  • Method: GET
  • URL: /accounts
  • Responses:
    • Success:
      • Status code: 200 - OK
      • Example body:
      [
        {
          "id": 53,
          "name": "account-test",
          "cpf": "97014963023",
          "secret": "$2a$10$L61LEOytm.hUNSeq897S0eBhPwx14hMogi9wZ7EsHCsK115e2Oh7G",
          "balance": 100,
          "created_at": "2022-07-24T18:25:20.21256-03:00"
        }
      ]
    • Errors:
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Get account balance:

  • Method: GET
  • URL: /accounts/{account_id}/balance
  • Responses:
    • Success:
      • Status code: 200 - OK
      • Example body:
      {
        "balance": 100
      }
    • Errors:
      • Account not fount
        • Status code: 404 - Not Found
        • Example body:
        {
          "error": "record not found"
        }
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Authenticate user:

  • Method: POST
  • URL: /login
  • Body:
    {
      "cpf": "97014963023",
      "secret": "u69UFv$*ETH4"
    }
  • Responses:
    • Success:
      • Status code: 200 - OK
      • Example body:
      {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjo1MiwiZXhwIjoxNjU5MjI2MzkyfQ.xdoh-98tbj04-aYp7AtIiucI3YKvWZ5DvjvMoj9FZEo"
      }
    • Errors:
      • Account not fount
        • Status code: 404 - Not Found
        • Example body:
        {
          "error": "account not found"
        }
      • Unauthorized login
        • Status code: 401 - Unauthorized
      • Request with invalid syntax
        • Status code: 400 - Bad Request
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Transfer between accounts:

  • Method: POST
  • URL: /transfers
  • Authorization: Bearer Token
  • Body:
    {
      "account_destination_id": 54,
      "amount": 50
    }
  • Responses:
    • Success:
      • Status code: 200 - OK
      • Example body:
      {
        "transaction_id": 1
      }
    • Errors:
      • Insufficient balance for transfer
        • Status code: 412 - Precondition Failed
        • Example body:
        {
          "error": "insufficient balance for transfer"
        }
      • Unauthorized user
        • Status code: 401 - Unauthorized
      • Request with invalid syntax
        • Status code: 400 - Bad Request
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Get transfer list from authenticated user:

  • Method: GET
  • URL: /transfers
  • Responses:
    • Success:
      • Status code: 200 - OK
      • Example body:
      [
        {
          "id": 1,
          "account_origin_id": 53,
          "account_destination_id": 54,
          "amount": 50,
          "created_at": "2022-07-24T18:25:20.21256-03:00"
        }
      ]
    • Errors:
      • Unauthorized user
        • Status code: 401 - Unauthorized
      • Internal Server Error
        • Status code: 500 - Internal Server Error

Rules:

  • Account:

    • name, cpf, and secret are required
    • cpf must contain 11 characters
    • secret must contain at least 8 characters
    • secret must be saved as hash
    • the default balance amount is 0
    • only one account per CPF
  • Login:

    • cpf and secret are required
    • returns the token to be used in authenticated routes
    • the generated token is valid for 1 hour
  • Transfer:

    • account_destination_id and amount are required
    • use bearer token authentication
    • the transfer amount must be greater than 0 and the account balance must be >= the amount to be transferred

banking-api's People

Contributors

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