Refactor files

This commit is contained in:
Santiago Lo Coco 2022-11-28 17:24:28 -03:00
parent 44f1ff9f17
commit 26cb63ba22
19 changed files with 27 additions and 41 deletions

View File

@ -1,10 +1,10 @@
from dotenv import load_dotenv from dotenv import load_dotenv
from fastapi import FastAPI from fastapi import FastAPI
from api.components.document import documents_routes from bsition.api.components.document import documents_routes
from api.components.user import users_routes from bsition.api.components.user import users_routes
from api.components.table import tables_routes from bsition.api.components.table import tables_routes
from api.routes.auth import auth_routes from bsition.api.routes.auth import auth_routes
app = FastAPI() app = FastAPI()
app.include_router(auth_routes, prefix="/api") app.include_router(auth_routes, prefix="/api")

View File

@ -4,9 +4,9 @@ from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
from pydantic.types import Optional from pydantic.types import Optional
import backend.elastic as elastic from bsition.backend import mongo
import backend.mongo as mongo from bsition.backend import elastic
from api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
documents_routes = APIRouter(route_class=VerifyTokenRoute) documents_routes = APIRouter(route_class=VerifyTokenRoute)

View File

@ -1,11 +1,9 @@
import json
from fastapi import APIRouter, Response, status from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
from pydantic.utils import Optional from pydantic.utils import Optional
import backend.postgres as postgres from bsition.backend import postgres
from api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
tables_routes = APIRouter(route_class=VerifyTokenRoute) tables_routes = APIRouter(route_class=VerifyTokenRoute)

View File

@ -1,10 +1,8 @@
import json
from fastapi import APIRouter, Response, status from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
import backend.postgres as postgres from bsition.backend import postgres
from api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
users_routes = APIRouter() users_routes = APIRouter()

View File

@ -1,7 +1,7 @@
from fastapi import Request from fastapi import Request
from fastapi.routing import APIRoute from fastapi.routing import APIRoute
from api.jwt import validate_token from bsition.api.jwt import validate_token
class VerifyTokenRoute(APIRoute): class VerifyTokenRoute(APIRoute):

View File

@ -1,9 +1,9 @@
from fastapi import APIRouter, Header from fastapi import APIRouter
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from pydantic import BaseModel, EmailStr from pydantic import BaseModel
from api.jwt import validate_token, write_token from bsition.api.jwt import write_token
from backend.postgres import get_user_by_username from bsition.backend.postgres import get_user_by_username
auth_routes = APIRouter() auth_routes = APIRouter()
@ -18,9 +18,3 @@ def login(user: User):
return write_token(user.dict()) return write_token(user.dict())
else: else:
return JSONResponse(content={"message": "User not found"}, status_code=404) return JSONResponse(content={"message": "User not found"}, status_code=404)
# @auth_routes.post("/token")
# def verify_token(Authorization: str = Header(None)):
# token = Authorization.split(" ")[1]
# return validate_token(token, output=True)

View File

@ -1,7 +1,7 @@
from dotenv import load_dotenv from dotenv import load_dotenv
from backend.postgres import * from bsition.backend.postgres import *
from backend.elastic import * from bsition.backend.elastic import *
def configure(): def configure():

View File

@ -3,7 +3,7 @@ from os import getenv
from bson import ObjectId from bson import ObjectId
from pymongo import MongoClient from pymongo import MongoClient
import backend.elastic as elastic from bsition.backend import elastic
def get_database(): def get_database():
@ -14,7 +14,8 @@ def get_database():
def get_documents(): def get_documents():
dbname = get_database() dbname = get_database()
docs_coll = dbname["docs"] docs_coll = dbname["docs"]
return list(docs_coll.find({}, {"_id": 0})) pipeline = [{'$project': {"id": {'$toString': "$_id"}, "_id": 0, "data": 1, "name": 1, "access": 1, "owner": 1}}]
return list(docs_coll.aggregate(pipeline))
def create_document(document): def create_document(document):

View File

@ -1,12 +1,11 @@
import inspect import inspect
from os import getenv from os import getenv
import psycopg2 from psycopg2 import sql, connect
from psycopg2 import sql
def get_connection(): def get_connection():
return psycopg2.connect( return connect(
host=getenv("POSTGRES_HOST"), host=getenv("POSTGRES_HOST"),
database=getenv("POSTGRES_DB"), database=getenv("POSTGRES_DB"),
user=getenv("POSTGRES_USER"), user=getenv("POSTGRES_USER"),

View File

@ -222,7 +222,7 @@
"response": [] "response": []
}, },
{ {
"name": "Update document", "name": "Update document (cambiar document_id)",
"request": { "request": {
"method": "PUT", "method": "PUT",
"header": [], "header": [],
@ -795,7 +795,7 @@
"bearer": [ "bearer": [
{ {
"key": "token", "key": "token",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJleHAiOjE2Njk4MjYzNDd9.GvPd8qrh0v21clmXuVtdAOFvhJafhC3vjdNSiS7e5YU", "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJleHAiOjE2Njk4Mjc4MDR9._9Fp7DLOJ2Rt_brG4oZp8wqLuDdIiwjGpodbHMrLaX0",
"type": "string" "type": "string"
} }
] ]

View File

@ -9,10 +9,6 @@ authors = [
] ]
license = "MIT" license = "MIT"
readme = "README.md" readme = "README.md"
packages = [
{ include = "backend" },
{ include = "api" }
]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.10" python = "^3.10"
@ -42,4 +38,4 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts] [tool.poetry.scripts]
configure = "backend.configure:configure" configure = "bsition.backend.configure:configure"

2
run.sh
View File

@ -26,7 +26,7 @@ if [ "$RUN" = 'install' ]; then
poetry install poetry install
elif [ "$RUN" = 'api' ]; then elif [ "$RUN" = 'api' ]; then
poetry shell poetry shell
uvicorn api.api:app --host 0.0.0.0 uvicorn bsition.api.api:app --host 0.0.0.0
elif [ "$RUN" = 'configure' ]; then elif [ "$RUN" = 'configure' ]; then
poetry run configure poetry run configure
else else