Run pre-commit

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2022-11-29 11:14:56 -03:00
parent ec80c1a96c
commit 0799aea56a
7 changed files with 16 additions and 14 deletions

View File

@ -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. 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. En esta colección se muestra, a grandes rasgos, el funcionamiento de la API.

View File

@ -1,7 +1,7 @@
from fastapi import APIRouter from fastapi import APIRouter
from fastapi.responses import JSONResponse 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() router = APIRouter()

View File

@ -1,8 +1,8 @@
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from bsition.api.utils.jwt import write_token
from bsition.api.models.user import User 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 from bsition.backend.postgres import get_user_by_username_and_password
router = APIRouter() router = APIRouter()
@ -12,11 +12,9 @@ router = APIRouter()
def login(user: User): def login(user: User):
if get_user_by_username_and_password(user.username, user.password) is not None: if get_user_by_username_and_password(user.username, user.password) is not None:
return JSONResponse( return JSONResponse(
content={ content={"access_token": write_token(user.dict()), "token_type": "bearer"},
"access_token": write_token(user.dict()), status_code=202,
"token_type": "bearer" )
},
status_code=202)
else: else:
raise HTTPException( raise HTTPException(
status_code=400, status_code=400,

View File

@ -2,7 +2,7 @@ from fastapi import APIRouter
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from bsition.api.middleware.verify_token import VerifyTokenRoute 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 from bsition.backend import postgres
router = APIRouter(route_class=VerifyTokenRoute) router = APIRouter(route_class=VerifyTokenRoute)

View File

@ -10,7 +10,10 @@ router = APIRouter()
@router.post("") @router.post("")
def create_user(user: User): 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( raise HTTPException(
status_code=400, status_code=400,
detail="User already exists.", detail="User already exists.",

View File

@ -1,5 +1,6 @@
from fastapi import FastAPI
from dotenv import load_dotenv from dotenv import load_dotenv
from fastapi import FastAPI
from bsition.api.api import router from bsition.api.api import router
app = FastAPI() app = FastAPI()

View File

@ -286,9 +286,9 @@ def get_user_by_username_and_password(username, password):
conn = get_connection() conn = get_connection()
cur = conn.cursor() cur = conn.cursor()
cur.execute( cur.execute(
sql.SQL("SELECT * FROM users WHERE username = {username} AND password = {password}").format( sql.SQL(
username=sql.Literal(username), password=sql.Literal(password) "SELECT * FROM users WHERE username = {username} AND password = {password}"
) ).format(username=sql.Literal(username), password=sql.Literal(password))
) )
return cur.fetchone() return cur.fetchone()