Skip to content

Commit

Permalink
Atualiza imports para deploy na vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
joao15victor08 committed May 13, 2024
1 parent eab13c7 commit cc486f6
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ unb_tv.egg-info
data/postgress
.pytest_cache
data
.coverage
.coverage
.vercel
13 changes: 13 additions & 0 deletions index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import uvicorn
from dotenv import load_dotenv

load_dotenv()

from src.utils import dotenv

load_dotenv()
dotenv.validate_dotenv()

if __name__ == '__main__': # pragma: no cover
port = 8000
uvicorn.run('src.main:app', reload=True, port=int(port), host="0.0.0.0")
12 changes: 5 additions & 7 deletions src/controller/authController.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
from fastapi import APIRouter, HTTPException, Response, status, Depends
from utils import security, enumeration, send_mail
from database import get_db
from src.utils import security, enumeration, send_mail
from src.database.database import get_db
from sqlalchemy.orm import Session
from datetime import datetime, timedelta
from constants import errorMessages
from src.constants import errorMessages
from starlette.responses import JSONResponse

from domain import userSchema, authSchema
from repository import userRepository
import secrets
from src.domain import userSchema, authSchema
from src.repository import userRepository

auth = APIRouter(
prefix="/auth"
Expand Down
10 changes: 5 additions & 5 deletions src/controller/userController.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from fastapi import APIRouter, HTTPException, Response, status, Depends, Header
from database import get_db
from src.database.database import get_db
from sqlalchemy.orm import Session

from constants import errorMessages
from domain import userSchema
from repository import userRepository
from utils import security, enumeration
from src.constants import errorMessages
from src.domain import userSchema
from src.repository import userRepository
from src.utils import security, enumeration

from fastapi_filter import FilterDepends

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/domain/userSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 src.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)
Expand Down
24 changes: 10 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import uvicorn, sys
# import uvicorn, sys
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv

from utils import dotenv

load_dotenv()
dotenv.validate_dotenv()
from src.controller import userController, authController
from src.model import userModel
from src.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()

Expand All @@ -35,9 +31,9 @@
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")
# uvicorn.run('main:app', reload=True, port=int(port), host="0.0.0.0")
2 changes: 1 addition & 1 deletion src/model/userModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from database import Base
from src.database.database import Base

class User(Base):
__tablename__ = "users"
Expand Down
6 changes: 2 additions & 4 deletions src/repository/userRepository.py
Original file line number Diff line number Diff line change
@@ -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 src.domain import userSchema
from src.model import userModel

# Obtem usuario a partir do seu ID
def get_user(db: Session, user_id: int):
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dotenv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from constants import errorMessages
from src.constants import errorMessages

def validate_dotenv():
required_env_var = ["SECRET", "ALGORITHM", "MAIL_USERNAME", "MAIL_PASSWORD", "MAIL_FROM", "MAIL_PORT", "MAIL_SERVER"]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from passlib.context import CryptContext
from jose import JWTError, jwt
from fastapi.security import OAuth2PasswordBearer
from constants import errorMessages
from src.constants import errorMessages

SECRET_KEY = os.getenv("SECRET")
ALGORITHM = os.getenv("ALGORITHM")
Expand Down
2 changes: 1 addition & 1 deletion src/utils/send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel, EmailStr
from starlette.responses import JSONResponse
from typing import List
from domain import authSchema
from src.domain import authSchema

conf = ConnectionConfig(
MAIL_USERNAME = os.getenv("MAIL_USERNAME"),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from src.constants import errorMessages
from src.model import userModel
from src.utils import security, dotenv, send_mail, enumeration
from src.database import get_db, engine, Base
from src.database.database import get_db, engine, Base

valid_user_active_admin = {"name": "Forsen", "email": "[email protected]", "connection": "PROFESSOR", "password": "123456"}
valid_user_active_user = {"name": "Guy Beahm", "email": "[email protected]", "connection": "ESTUDANTE", "password": "123456"}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from src.main import app
from src.constants import errorMessages
from src.database import get_db, engine, Base
from src.database.database import get_db, engine, Base
from tests import test_auth

valid_user_active_admin = test_auth.valid_user_active_admin
Expand Down
15 changes: 15 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"builds": [
{
"src": "src/main.py",
"use": "@vercel/python",
"config": {"maxLambdaSize": "15mb"}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/main.py"
}
]
}

0 comments on commit cc486f6

Please sign in to comment.