Skip to content

Marrowsed/Financial_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Financial APP CodeQL DjangoREST Postgres Python

🪧 Vitrine.Dev
✨ Nome Financial API
🏷️ Tecnologias python, django, django-rest, postgresql
🚀 URL https://financial-rest-app.herokuapp.com/
🔥 Desafio https://www.alura.com.br/challenges/back-end-4?host=https://cursos.alura.com.br

Tecnologies and Frameworks

Django Rest Framework

  • Django - O propósito do Django está no desenvolvimento de aplicações web e sites.
  • Django Rest Framework - Desenvolvimento de web API'S de forma simples e ágil.

Financial API

Try now live !

Make a [POST] Request at: https://financial-rest-app.herokuapp.com/register/ and get your Token !

Swagger Generated Doc:

Pretty Doc

Your control by:

Methods

  • GET - Return Info
  • POST - Insert Info
  • PUT - Update Info
  • DELETE - Delete Info

Endpoints

Register [POST]

Create your account for Bearer Token Generate !

Request example:

[
  {
    "username": "john",
    "password": "P4ssw0rd",
    "password2": "P4ssw0rd",
    "email": "johndoe@doe.com",
    "first_name": "John",
    "last_name": "Doe"
  }
]

201 Return:

[
  {
    "username": "john",
    "email": "johndoe@doe.com",
    "first_name": "John",
    "last_name": "Doe"
  }
]

Bad Request:

[
  {
    "detail": "Registry already exists"
  }
]

Bearer Token [POST]

What is a Bearer Token ?

Access Token and Refresh Token Generator. Each 15 minutes you have to generate a new Access Token.

  • /token/ [POST]
  • Generate Access and Refresh Token. If you lose the refresh token, you'll have to generate another

    P.S: Refresh Token expires in 1 day !

Request example:

[
  {
    "username": "john",
    "password": "P4ssw0rd"
  }
]

20x Return:

[
  {
    "refresh": "YOUR_REFRESH_TOKEN",
    "access": "YOUR_ACCESS_TOKEN"
  }
]

Bad Request:

[
  {
    "detail": "User and/or password incorrect"
  }
]
  • /token/refresh/ [POST]
  • Refresh the expired Access Token !

Request example:

[
  {
    "refresh": "YOUR_REFRESH_TOKEN"
  }
]

20x Return:

[
  {
    "access": "NEW_ACCESS_TOKEN"
  }
]

Bad Request:

[
 {
   "detail": "Invalid or expired Token",
   "code": "token_not_valid"
 }
]
  • /token/verify/ [POST]
  • Verify the Access Token !

Request example:

[
  {
    "token": "YOUR_ACCESS_TOKEN"
  }
]

200 Return:

[
  {
    
  }
]

Bad Request:

[
 {
   "detail": "Invalid or expired Token",
   "code": "token_not_valid"
 }
]

Revenue [GET/POST/PUT/DELETE]

Authentication

    Bearer Token
  • Bearer "YOUR_ACCESS_TOKEN"

Endpoints

  • /revenue/ [GET]
  • Revenue List
  • /revenue/ [POST]
  • Insert a new Revenue
  • /revenue/{pk}/ [PUT/DELETE]
  • Update / Delete a Revenue
  • /revenue/{yyyy}/{mm} [GET]
  • List the filter revenue
  • /revenue/?description= [GET]
  • List the revenue description

Request example:

[
  {
    "description": "Revenue Description",
    "value": 1000,
    "date": "2000-12-25"
  }
]

20x Return:

[
  {
    "id": "Revenue ID",
    "description": "Revenue Description",
    "value": 1000,
    "date": "2000-12-25"
  }
]

Bad Request:

[
  {
    "detail": "Registry already exists"
  }
]

Expense [GET/POST/PUT/DELETE]

Categories Available: Food, Health, Home, Transport, School, Fun, Unexpected, Other

Authentication

    Bearer Token
  • Bearer "YOUR_ACCESS_TOKEN"

Endpoints

  • /expense/ [GET]
  • Expense List
  • /expense/ [POST]
  • Insert a new Expense
  • /expense/{pk}/ [PUT/DELETE]
  • Update / Delete a Registry
  • /expense/{yyyy}/{mm} [GET]
  • List the filter Expense
  • /expense/?description= [GET]
  • Expense by description

Request example:

[
  {
    "description": "Expense Description",
    "value": 1000,
    "category": "Food",
    "date": "2000-12-25"
  }
]

20x Response:

[
  {
    "id": "Expense ID",
    "description": "Expense Description",
    "category": "Expense Category",
    "value": 1000,
    "date": "2000-12-25"
  }
]

Bad Request:

[
  {
    "detail": "Registry already exists"
  }
]

Summary [GET]

Summary of the month with the % of expenses by category

Authentication

    Bearer Token
  • Bearer "YOUR_ACCESS_TOKEN"

Endpoints

  • /summary/{yyyy}/{mm} [GET]
200 Example:
[
  {
    "Revenue/Month": 5000,
    "Expense/Month": 2000,
    "Final Value": 3000,
    "Category": [
      "Category: $500 - 50%", 
      "Another Category: $500 - 50%"
    ]
  }
]

Bad Request:

[
  {
    "detail": "No registry"
  }
]

Install

Python latest

Dependencies

pip install -r requirements.txt

Config

  1. Create an `.env` file in the same folder where `migrate.py` is.
  2. In your terminal with venv, execute `python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'` generating a new secret key
  3. Insert the new secret key in `.env` file like this: `SECRET_KEY = oahsdodjifodjfodjfpadjpajsdpojsd` .
  4. Insert the database URL in the `.env` file like this: `DATABASE_URL = your_db://your_db:password@localhost/my_db`.
  5. Run `python manage.py migrate` and create the tables

Running

python manage.py runserver

Server is running in http://127.0.0.1:8000/, access your browser !

Releases

No releases published

Packages

No packages published