diff --git a/api/__init__.py b/bsition/api/__init__.py similarity index 100% rename from api/__init__.py rename to bsition/api/__init__.py diff --git a/api/api.py b/bsition/api/api.py similarity index 56% rename from api/api.py rename to bsition/api/api.py index ffc8702..e16fd6e 100644 --- a/api/api.py +++ b/bsition/api/api.py @@ -1,10 +1,10 @@ from dotenv import load_dotenv from fastapi import FastAPI -from api.components.document import documents_routes -from api.components.user import users_routes -from api.components.table import tables_routes -from api.routes.auth import auth_routes +from bsition.api.components.document import documents_routes +from bsition.api.components.user import users_routes +from bsition.api.components.table import tables_routes +from bsition.api.routes.auth import auth_routes app = FastAPI() app.include_router(auth_routes, prefix="/api") diff --git a/api/components/__init__.py b/bsition/api/components/__init__.py similarity index 100% rename from api/components/__init__.py rename to bsition/api/components/__init__.py diff --git a/api/components/document.py b/bsition/api/components/document.py similarity index 90% rename from api/components/document.py rename to bsition/api/components/document.py index 13df546..cf40894 100644 --- a/api/components/document.py +++ b/bsition/api/components/document.py @@ -4,9 +4,9 @@ from fastapi import APIRouter, Response, status from pydantic import BaseModel from pydantic.types import Optional -import backend.elastic as elastic -import backend.mongo as mongo -from api.middleware.verify_token import VerifyTokenRoute +from bsition.backend import mongo +from bsition.backend import elastic +from bsition.api.middleware.verify_token import VerifyTokenRoute documents_routes = APIRouter(route_class=VerifyTokenRoute) diff --git a/api/components/table.py b/bsition/api/components/table.py similarity index 95% rename from api/components/table.py rename to bsition/api/components/table.py index 9c950c0..f6287be 100644 --- a/api/components/table.py +++ b/bsition/api/components/table.py @@ -1,11 +1,9 @@ -import json - from fastapi import APIRouter, Response, status from pydantic import BaseModel from pydantic.utils import Optional -import backend.postgres as postgres -from api.middleware.verify_token import VerifyTokenRoute +from bsition.backend import postgres +from bsition.api.middleware.verify_token import VerifyTokenRoute tables_routes = APIRouter(route_class=VerifyTokenRoute) diff --git a/api/components/user.py b/bsition/api/components/user.py similarity index 88% rename from api/components/user.py rename to bsition/api/components/user.py index 4de16fa..f8e0eb3 100644 --- a/api/components/user.py +++ b/bsition/api/components/user.py @@ -1,10 +1,8 @@ -import json - from fastapi import APIRouter, Response, status from pydantic import BaseModel -import backend.postgres as postgres -from api.middleware.verify_token import VerifyTokenRoute +from bsition.backend import postgres +from bsition.api.middleware.verify_token import VerifyTokenRoute users_routes = APIRouter() diff --git a/api/jwt.py b/bsition/api/jwt.py similarity index 100% rename from api/jwt.py rename to bsition/api/jwt.py diff --git a/api/middleware/__init__.py b/bsition/api/middleware/__init__.py similarity index 100% rename from api/middleware/__init__.py rename to bsition/api/middleware/__init__.py diff --git a/api/middleware/verify_token.py b/bsition/api/middleware/verify_token.py similarity index 93% rename from api/middleware/verify_token.py rename to bsition/api/middleware/verify_token.py index 1a8e7ae..5428bed 100644 --- a/api/middleware/verify_token.py +++ b/bsition/api/middleware/verify_token.py @@ -1,7 +1,7 @@ from fastapi import Request from fastapi.routing import APIRoute -from api.jwt import validate_token +from bsition.api.jwt import validate_token class VerifyTokenRoute(APIRoute): diff --git a/api/routes/__init__.py b/bsition/api/routes/__init__.py similarity index 100% rename from api/routes/__init__.py rename to bsition/api/routes/__init__.py diff --git a/api/routes/auth.py b/bsition/api/routes/auth.py similarity index 50% rename from api/routes/auth.py rename to bsition/api/routes/auth.py index 31ee1b9..8cc8022 100644 --- a/api/routes/auth.py +++ b/bsition/api/routes/auth.py @@ -1,9 +1,9 @@ -from fastapi import APIRouter, Header +from fastapi import APIRouter from fastapi.responses import JSONResponse -from pydantic import BaseModel, EmailStr +from pydantic import BaseModel -from api.jwt import validate_token, write_token -from backend.postgres import get_user_by_username +from bsition.api.jwt import write_token +from bsition.backend.postgres import get_user_by_username auth_routes = APIRouter() @@ -18,9 +18,3 @@ def login(user: User): return write_token(user.dict()) else: 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) diff --git a/backend/__init__.py b/bsition/backend/__init__.py similarity index 100% rename from backend/__init__.py rename to bsition/backend/__init__.py diff --git a/backend/configure.py b/bsition/backend/configure.py similarity index 65% rename from backend/configure.py rename to bsition/backend/configure.py index 20df9fe..b5185fc 100644 --- a/backend/configure.py +++ b/bsition/backend/configure.py @@ -1,7 +1,7 @@ from dotenv import load_dotenv -from backend.postgres import * -from backend.elastic import * +from bsition.backend.postgres import * +from bsition.backend.elastic import * def configure(): diff --git a/backend/elastic.py b/bsition/backend/elastic.py similarity index 100% rename from backend/elastic.py rename to bsition/backend/elastic.py diff --git a/backend/mongo.py b/bsition/backend/mongo.py similarity index 87% rename from backend/mongo.py rename to bsition/backend/mongo.py index 692c7d8..4f5ae68 100644 --- a/backend/mongo.py +++ b/bsition/backend/mongo.py @@ -3,7 +3,7 @@ from os import getenv from bson import ObjectId from pymongo import MongoClient -import backend.elastic as elastic +from bsition.backend import elastic def get_database(): @@ -14,7 +14,8 @@ def get_database(): def get_documents(): dbname = get_database() 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): diff --git a/backend/postgres.py b/bsition/backend/postgres.py similarity index 99% rename from backend/postgres.py rename to bsition/backend/postgres.py index a54d151..b4af75c 100644 --- a/backend/postgres.py +++ b/bsition/backend/postgres.py @@ -1,12 +1,11 @@ import inspect from os import getenv -import psycopg2 -from psycopg2 import sql +from psycopg2 import sql, connect def get_connection(): - return psycopg2.connect( + return connect( host=getenv("POSTGRES_HOST"), database=getenv("POSTGRES_DB"), user=getenv("POSTGRES_USER"), diff --git a/docs/bsition_postman.json b/docs/bsition_postman.json index 55d2f10..b505614 100644 --- a/docs/bsition_postman.json +++ b/docs/bsition_postman.json @@ -222,7 +222,7 @@ "response": [] }, { - "name": "Update document", + "name": "Update document (cambiar document_id)", "request": { "method": "PUT", "header": [], @@ -795,7 +795,7 @@ "bearer": [ { "key": "token", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJleHAiOjE2Njk4MjYzNDd9.GvPd8qrh0v21clmXuVtdAOFvhJafhC3vjdNSiS7e5YU", + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJleHAiOjE2Njk4Mjc4MDR9._9Fp7DLOJ2Rt_brG4oZp8wqLuDdIiwjGpodbHMrLaX0", "type": "string" } ] diff --git a/pyproject.toml b/pyproject.toml index 4f252cc..b89e9ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,10 +9,6 @@ authors = [ ] license = "MIT" readme = "README.md" -packages = [ - { include = "backend" }, - { include = "api" } -] [tool.poetry.dependencies] python = "^3.10" @@ -42,4 +38,4 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] -configure = "backend.configure:configure" +configure = "bsition.backend.configure:configure" diff --git a/run.sh b/run.sh index 8e744a3..887b46d 100644 --- a/run.sh +++ b/run.sh @@ -26,7 +26,7 @@ if [ "$RUN" = 'install' ]; then poetry install elif [ "$RUN" = 'api' ]; then 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 poetry run configure else