Skip to content

Commit 47bb361

Browse files
committed
feat: new structure
1 parent dd6d314 commit 47bb361

File tree

13 files changed

+99
-77
lines changed

13 files changed

+99
-77
lines changed

backend/app/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from fastapi import APIRouter
2+
from app.api.api_v1.endpoints import overlay
3+
4+
api_router = APIRouter()
5+
api_router.include_router(overlay.router, prefix="/overlay", tags=["overlay"])

backend/app/api/v1/endpoints/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from fastapi import APIRouter, Depends
2+
from sqlalchemy.ext.asyncio import AsyncSession
3+
from sqlalchemy.orm import Session
4+
from app.schemas.user import UserCreate
5+
from app.crud.user import create_user
6+
from app.db.session import get_db
7+
8+
router = APIRouter()
9+
10+
@router.get("/", response_model=list[Overlay])
11+
async def get_overlays(session: AsyncSession = Depends(get_db)):
12+
result = await session.execute(select(Overlay))
13+
overlays = result.scalars().all()
14+
return [Overlay(riotId=overlay.riotId, hdevApiKey=overlay.hdevApiKey, uuid=overlay.uuid) for overlay in overlays]
15+
16+
@router.get("/{overlay_id}", response_model=OverlaySchema)
17+
async def get_overlay(overlay_id: str, session: AsyncSession = Depends(get_db)):
18+
result = await session.execute(select(Overlay).filter(Overlay.uuid == overlay_id))
19+
overlay = result.scalars().first()
20+
if overlay is None:
21+
raise HTTPException(status_code=404, detail="Overlay not found")
22+
return overlay
23+
24+
@router.post("/")
25+
async def add_overlay(overlay: OverlayCreate, session: AsyncSession = Depends(get_db)):
26+
overlay = Overlay(riotId=overlay.riotId, hdevApiKey=overlay.hdevApiKey)
27+
session.add(overlay)
28+
await session.commit()
29+
await session.refresh(overlay)
30+
return overlay

backend/app/crud/__init__.py

Whitespace-only changes.

backend/app/db.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

backend/app/db/__init__.py

Whitespace-only changes.

backend/app/db/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from sqlalchemy.ext.declarative import declarative_base
2+
3+
Base = declarative_base()

backend/app/db/session.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
2+
from sqlalchemy.orm import sessionmaker
3+
from sqlmodel import SQLModel
4+
5+
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
6+
engine = create_async_engine(DATABASE_URL, echo=True, future=True)
7+
8+
AsyncSessionLocal = sessionmaker(
9+
bind=engine,
10+
class_=AsyncSession,
11+
expire_on_commit=False,
12+
)
13+
14+
async def get_db() -> AsyncSession:
15+
async with AsyncSessionLocal() as session:
16+
yield session
17+
18+
async def init_db():
19+
async with engine.begin() as conn:
20+
await conn.run_sync(SQLModel.metadata.create_all)

backend/app/main.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

backend/app/schemas/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)