diff --git a/.gitignore b/.gitignore index 8f01f7c..71be848 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ data/postgress .pytest_cache data .coverage -*junit* \ No newline at end of file +*junit* +.vercel \ No newline at end of file diff --git a/index.py b/index.py new file mode 100644 index 0000000..277a846 --- /dev/null +++ b/index.py @@ -0,0 +1,13 @@ +import uvicorn +from dotenv import load_dotenv + +load_dotenv() + +from utils import dotenv + +load_dotenv() +dotenv.validate_dotenv() + +if __name__ == '__main__': # pragma: no cover + port = 8000 + uvicorn.run(' main:app', reload=True, port=int(port), host="0.0.0.0") \ No newline at end of file diff --git a/src/controller/authController.py b/src/controller/authController.py index 2ce6a6f..9586b89 100644 --- a/src/controller/authController.py +++ b/src/controller/authController.py @@ -2,17 +2,16 @@ import re from typing import List from fastapi import APIRouter, HTTPException, Response, status, Depends -from utils import security, enumeration, send_mail -from database import get_db +from utils import security, enumeration, send_mail +from database.database import get_db from sqlalchemy.orm import Session from datetime import datetime, timedelta -from constants import errorMessages +from constants import errorMessages from starlette.responses import JSONResponse from utils import security, enumeration -from domain import userSchema, authSchema -from repository import userRepository -import secrets +from domain import userSchema, authSchema +from repository import userRepository auth = APIRouter( prefix="/auth" diff --git a/src/controller/userController.py b/src/controller/userController.py index 6452978..d4ddbbc 100644 --- a/src/controller/userController.py +++ b/src/controller/userController.py @@ -1,5 +1,5 @@ from fastapi import APIRouter, HTTPException, Response, status, Depends, Header -from database import get_db +from database.database import get_db from sqlalchemy.orm import Session from constants import errorMessages diff --git a/src/domain/models/__init__.py b/src/database/__init__.py similarity index 100% rename from src/domain/models/__init__.py rename to src/database/__init__.py diff --git a/src/database.py b/src/database/database.py similarity index 100% rename from src/database.py rename to src/database/database.py diff --git a/src/domain/userSchema.py b/src/domain/userSchema.py index 2e63850..4689ea9 100644 --- a/src/domain/userSchema.py +++ b/src/domain/userSchema.py @@ -3,12 +3,12 @@ from fastapi_filter import FilterDepends, with_prefix from sqlalchemy import or_ from fastapi_filter.contrib.sqlalchemy import Filter -from model import userModel +from model import userModel class UserUpdate(BaseModel): - name: str | None = None - email: str | None = None - connection: str | None = None + name: str = None + email: str = None + connection: str = None class User(BaseModel): model_config = ConfigDict(from_attributes = True) diff --git a/src/main.py b/src/main.py index e2db9a9..e44b235 100644 --- a/src/main.py +++ b/src/main.py @@ -1,19 +1,16 @@ -import uvicorn, sys +# import uvicorn, sys from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from dotenv import load_dotenv from starlette.middleware.base import BaseHTTPMiddleware -from utils import dotenv -load_dotenv() -dotenv.validate_dotenv() +from controller import userController, authController +from model import userModel +from database import database -from controller import userController, authController -from database import engine -from model import userModel -userModel.Base.metadata.create_all(bind=engine) +userModel.Base.metadata.create_all(bind=database.engine) app = FastAPI() @@ -46,9 +43,9 @@ async def dispatch(self, request, call_next): def read_root(): return {"message": "UnB-TV!"} -if __name__ == '__main__': # pragma: no cover - port = 8000 - if (len(sys.argv) == 2): - port = sys.argv[1] +# if __name__ == '__main__': # pragma: no cover +# port = 8000 +# if (len(sys.argv) == 2): +# port = sys.argv[1] - uvicorn.run('main:app', reload=True, port=int(port), host="0.0.0.0") \ No newline at end of file +# uvicorn.run('main:app', reload=True, port=int(port), host="0.0.0.0") \ No newline at end of file diff --git a/src/model/userModel.py b/src/model/userModel.py index 4a7366e..7fa3cd5 100644 --- a/src/model/userModel.py +++ b/src/model/userModel.py @@ -3,7 +3,7 @@ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String from sqlalchemy.orm import relationship -from database import Base +from database.database import Base class User(Base): __tablename__ = "users" diff --git a/src/repository/userRepository.py b/src/repository/userRepository.py index a96afa2..78852c2 100644 --- a/src/repository/userRepository.py +++ b/src/repository/userRepository.py @@ -1,11 +1,9 @@ -from repository import userRepository - # Referencia: https://fastapi.tiangolo.com/tutorial/sql-databases/#crud-utils from sqlalchemy import or_ from sqlalchemy.orm import Session -from domain import userSchema -from model import userModel +from domain import userSchema +from model import userModel # Obtem usuario a partir do seu ID def get_user(db: Session, user_id: int): diff --git a/src/utils/dotenv.py b/src/utils/dotenv.py index 5d9802b..69314ed 100644 --- a/src/utils/dotenv.py +++ b/src/utils/dotenv.py @@ -1,5 +1,5 @@ import os -from constants import errorMessages +from constants import errorMessages def validate_dotenv(): required_env_var = ["SECRET", "ALGORITHM", "MAIL_USERNAME", "MAIL_PASSWORD", "MAIL_FROM", "MAIL_PORT", "MAIL_SERVER"] diff --git a/src/utils/security.py b/src/utils/security.py index f398960..94d86ab 100644 --- a/src/utils/security.py +++ b/src/utils/security.py @@ -4,7 +4,7 @@ from passlib.context import CryptContext from jose import JWTError, jwt from fastapi.security import OAuth2PasswordBearer -from constants import errorMessages +from constants import errorMessages SECRET_KEY = os.getenv("SECRET") ALGORITHM = os.getenv("ALGORITHM") diff --git a/src/utils/send_mail.py b/src/utils/send_mail.py index d837bbd..de667a5 100644 --- a/src/utils/send_mail.py +++ b/src/utils/send_mail.py @@ -5,7 +5,7 @@ from pydantic import BaseModel, EmailStr from starlette.responses import JSONResponse from typing import List -from domain import authSchema +from domain import authSchema conf = ConnectionConfig( MAIL_USERNAME = os.getenv("MAIL_USERNAME"), diff --git a/tests/test_user.py b/tests/test_user.py index a8021f9..67874af 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -8,9 +8,9 @@ import pytest from fastapi.testclient import TestClient -from src.main import app -from src.constants import errorMessages -from src.database import get_db, engine, Base +from main import app +from constants import errorMessages +from database.database import get_db, engine, Base from tests import test_auth valid_user_active_admin = test_auth.valid_user_active_admin diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..cfbd1ec --- /dev/null +++ b/vercel.json @@ -0,0 +1,15 @@ +{ + "builds": [ + { + "src": "src/main.py", + "use": "@vercel/python", + "config": {"maxLambdaSize": "15mb"} + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "src/main.py" + } + ] +}