From 0799aea56ae6f756e71f3eb3fb704ab14ecd7a85 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Tue, 29 Nov 2022 11:14:56 -0300 Subject: [PATCH] Run pre-commit Co-authored-by: Ezequiel Bellver Co-authored-by: Juan Barmasch --- README.md | 2 +- bsition/api/api.py | 2 +- bsition/api/endpoints/login.py | 10 ++++------ bsition/api/endpoints/tables.py | 2 +- bsition/api/endpoints/users.py | 5 ++++- bsition/api/main.py | 3 ++- bsition/backend/postgres.py | 6 +++--- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 11c99eb..1be79cb 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ sh run.sh -a Puede ir a `http://localhost:8000/docs` para ver el `Swagger`. Notemos que se usó en todo momento `localhost` pues se supone un ambiente de testeo. -Además, cuenta con una colección de `Postman` en [docs/bsition_postman.json](docs/bsition_postman.json). Consulte el siguiente [link](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/) para ver cómo se importa. +Además, cuenta con una colección de `Postman` en [docs/bsition_postman.json](docs/bsition_postman.json). Consulte el siguiente [link](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/) para ver cómo se importa. En esta colección se muestra, a grandes rasgos, el funcionamiento de la API. diff --git a/bsition/api/api.py b/bsition/api/api.py index 5493568..1ecd2f4 100644 --- a/bsition/api/api.py +++ b/bsition/api/api.py @@ -1,7 +1,7 @@ from fastapi import APIRouter from fastapi.responses import JSONResponse -from bsition.api.endpoints import documents, tables, users, login +from bsition.api.endpoints import documents, login, tables, users router = APIRouter() diff --git a/bsition/api/endpoints/login.py b/bsition/api/endpoints/login.py index 0f47c44..2260da6 100644 --- a/bsition/api/endpoints/login.py +++ b/bsition/api/endpoints/login.py @@ -1,8 +1,8 @@ from fastapi import APIRouter, HTTPException from fastapi.responses import JSONResponse -from bsition.api.utils.jwt import write_token from bsition.api.models.user import User +from bsition.api.utils.jwt import write_token from bsition.backend.postgres import get_user_by_username_and_password router = APIRouter() @@ -12,11 +12,9 @@ router = APIRouter() def login(user: User): if get_user_by_username_and_password(user.username, user.password) is not None: return JSONResponse( - content={ - "access_token": write_token(user.dict()), - "token_type": "bearer" - }, - status_code=202) + content={"access_token": write_token(user.dict()), "token_type": "bearer"}, + status_code=202, + ) else: raise HTTPException( status_code=400, diff --git a/bsition/api/endpoints/tables.py b/bsition/api/endpoints/tables.py index a21ca95..51a0e42 100644 --- a/bsition/api/endpoints/tables.py +++ b/bsition/api/endpoints/tables.py @@ -2,7 +2,7 @@ from fastapi import APIRouter from fastapi.responses import JSONResponse from bsition.api.middleware.verify_token import VerifyTokenRoute -from bsition.api.models.table import Table, Sort, Filter +from bsition.api.models.table import Filter, Sort, Table from bsition.backend import postgres router = APIRouter(route_class=VerifyTokenRoute) diff --git a/bsition/api/endpoints/users.py b/bsition/api/endpoints/users.py index 7623c7e..376e73c 100644 --- a/bsition/api/endpoints/users.py +++ b/bsition/api/endpoints/users.py @@ -10,7 +10,10 @@ router = APIRouter() @router.post("") def create_user(user: User): - if postgres.get_user_by_username_and_password(user.username, user.password) is not None: + if ( + postgres.get_user_by_username_and_password(user.username, user.password) + is not None + ): raise HTTPException( status_code=400, detail="User already exists.", diff --git a/bsition/api/main.py b/bsition/api/main.py index 29c46de..e9206b1 100644 --- a/bsition/api/main.py +++ b/bsition/api/main.py @@ -1,5 +1,6 @@ -from fastapi import FastAPI from dotenv import load_dotenv +from fastapi import FastAPI + from bsition.api.api import router app = FastAPI() diff --git a/bsition/backend/postgres.py b/bsition/backend/postgres.py index 9608a1f..2098219 100644 --- a/bsition/backend/postgres.py +++ b/bsition/backend/postgres.py @@ -286,9 +286,9 @@ def get_user_by_username_and_password(username, password): conn = get_connection() cur = conn.cursor() cur.execute( - sql.SQL("SELECT * FROM users WHERE username = {username} AND password = {password}").format( - username=sql.Literal(username), password=sql.Literal(password) - ) + sql.SQL( + "SELECT * FROM users WHERE username = {username} AND password = {password}" + ).format(username=sql.Literal(username), password=sql.Literal(password)) ) return cur.fetchone()