From c68170a2c61053a4b30c06abed4d8bd1ec9ced21 Mon Sep 17 00:00:00 2001 From: MAGICX Date: Tue, 3 Dec 2024 23:07:53 +0500 Subject: [PATCH] refactor(backend) --- backend/app/crud/overlay.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/backend/app/crud/overlay.py b/backend/app/crud/overlay.py index 0ce0a6b..114f400 100644 --- a/backend/app/crud/overlay.py +++ b/backend/app/crud/overlay.py @@ -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)