Skip to content

Commit

Permalink
refactor(backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
haxgun committed Dec 3, 2024
1 parent c90dcc9 commit c68170a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions backend/app/crud/overlay.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
from fastapi import APIRouter, Depends, HTTPException
from fastapi import HTTPException
from sqlmodel import select
from sqlmodel.ext.asyncio.session import AsyncSession
from app.models.overlay import Overlay
from app.db.session import get_db
from app.schemas.overlay import OverlayCreate

router = APIRouter()

async def get_overlays(session: AsyncSession = Depends(get_db)) -> list[Overlay]:
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 = Depends(get_db)) -> Overlay:
result = await session.execute(select(Overlay).where(Overlay.uuid == overlay_id))
overlay = result.scalars().first()
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: Overlay, session: AsyncSession = Depends(get_db)) -> Overlay:
new_overlay = Overlay(**overlay_data.dict(exclude_unset=True))
async def add_overlay(overlay_data: OverlayCreate, session: AsyncSession) -> Overlay:
new_overlay = Overlay(**overlay_data.dict())
session.add(new_overlay)
await session.commit()
await session.refresh(new_overlay)
Expand Down

0 comments on commit c68170a

Please sign in to comment.