Skip to content

Commit

Permalink
Merge branch 'merge-2024-1' into merge-2024-1
Browse files Browse the repository at this point in the history
  • Loading branch information
victorleaoo authored Sep 5, 2024
2 parents 0e6700d + a4e5107 commit 7f08013
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ data/postgress
.pytest_cache
data
.coverage
*junit*
*junit*
.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 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")
11 changes: 5 additions & 6 deletions src/controller/authController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/controller/userController.py
Original file line number Diff line number Diff line change
@@ -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
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 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
23 changes: 10 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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")
# 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 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 domain import userSchema
from 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 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 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 domain import authSchema

conf = ConnectionConfig(
MAIL_USERNAME = os.getenv("MAIL_USERNAME"),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 7f08013

Please sign in to comment.