Skip to content

Commit

Permalink
refactor: ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
haxgun committed Dec 4, 2024
1 parent 4f38f62 commit e0ff940
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions backend/app/api/v1/endpoints/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

router = APIRouter()


@router.get("/", response_model=list[OverlaySchema])
async def get_overlays(session: AsyncSession = Depends(get_db)):
return await overlay.get_overlays(session)


@router.get("/{overlay_id}", response_model=OverlaySchema)
async def get_overlay(overlay_id: str, session: AsyncSession = Depends(get_db)):
return await overlay.get_overlay(overlay_id, session)


@router.post("/", response_model=OverlaySchema)
async def add_overlay(overlay: OverlayCreate, session: AsyncSession = Depends(get_db)):
return await overlay.add_overlay(overlay, session)
3 changes: 3 additions & 0 deletions backend/app/crud/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
from app.models.overlay import Overlay
from app.schemas.overlay import OverlayCreate


async def get_overlays(session: AsyncSession) -> list[Overlay]:
result = await session.execute(select(Overlay))
overlays = result.scalars().all()
return overlays


async def get_overlay(overlay_id: str, session: AsyncSession) -> Overlay:
overlay = await session.get(Overlay, overlay_id)
if overlay is None:
raise HTTPException(status_code=404, detail="Overlay not found")
return overlay


async def add_overlay(overlay_data: OverlayCreate, session: AsyncSession) -> Overlay:
new_overlay = Overlay(**overlay_data.dict())
session.add(new_overlay)
Expand Down
2 changes: 2 additions & 0 deletions backend/app/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
expire_on_commit=False,
)


async def get_db() -> AsyncSession:
async with AsyncSessionLocal() as session:
yield session


async def init_db():
async with engine.begin() as conn:
await conn.run_sync(SQLModel.metadata.create_all)
12 changes: 5 additions & 7 deletions backend/app/schemas/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ class OverlaySchema(BaseModel):
riot_id: str
hdev_api_key: str

model_config = {
"from_attributes": True
}
model_config = {"from_attributes": True}


class OverlayCreate(OverlayBase):
pass
pass


class OverlayRead(OverlayBase):
uuid: uuid_pkg.UUID

model_config = {
"from_attributes": True
}
model_config = {"from_attributes": True}
16 changes: 9 additions & 7 deletions backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

from dotenv import load_dotenv


def str_to_bool(value: str) -> bool:
return value.lower() in ("true", "1", "yes")


BASE_DIR: str = Path(__file__).resolve().parent.parent.parent

dotenv_file: str = BASE_DIR / '.env'
dotenv_file: str = BASE_DIR / ".env"
if dotenv_file.is_file():
load_dotenv(dotenv_file)
else:
raise ImportError('⚠ .env was not found')
raise ImportError("⚠ .env was not found")


DEBUG: bool = str_to_bool(environ.get("DEBUG", "False"))

PROJECT_NAME: str = environ.get('PROJECT_NAME')
VERSION: str = environ.get('VERSION')
PROJECT_NAME: str = environ.get("PROJECT_NAME")
VERSION: str = environ.get("VERSION")

DATABASE_URL: str = environ.get('DATABASE_URL')
DEGUB_DATABASE_URL: str = environ.get('DEGUB_DATABASE_URL')
DATABASE_URL: str = environ.get("DATABASE_URL")
DEGUB_DATABASE_URL: str = environ.get("DEGUB_DATABASE_URL")

0 comments on commit e0ff940

Please sign in to comment.