-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
130 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
uv.lock | ||
sqlite.db | ||
.venv | ||
.ruff_cache | ||
Pipfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
aiosqlite = "*" | ||
alembic = "*" | ||
asyncpg = "*" | ||
fastapi = {extras = ["standard"], version = "*"} | ||
greenlet = "*" | ||
psycopg2-binary = "*" | ||
python-dotenv = "*" | ||
sqlalchemy = "*" | ||
sqlmodel = "*" | ||
uuid = "*" | ||
uvicorn = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.13" | ||
|
||
[scripts] | ||
dev = "fastapi dev main.py" |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from sqlalchemy.ext.asyncio import create_async_engine | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlmodel import SQLModel | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from app.settings import DATABASE_URL | ||
from app.models import overlays | ||
|
||
engine = create_async_engine(DATABASE_URL, echo=False) | ||
|
||
|
||
async def init_db(): | ||
async with engine.begin() as conn: | ||
await conn.run_sync(SQLModel.metadata.create_all) | ||
|
||
|
||
async def get_session(): | ||
async_session = sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False) | ||
async with async_session() as session: | ||
yield session |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import uuid | ||
|
||
from sqlmodel import SQLModel, Field | ||
|
||
|
||
class OverlayBase(SQLModel): | ||
riot_id: str | ||
hdev_api_key: str | ||
|
||
|
||
class Overlay(OverlayBase, table=True): | ||
id: uuid.UUID = Field( | ||
default_factory=uuid.uuid4, | ||
primary_key=True, | ||
nullable=False, | ||
) | ||
|
||
|
||
class OverlayCreate(OverlayBase): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.routers import overlays | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(overlays.router, prefix="/overlay", tags=["overlay"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import uuid | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlmodel import select | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from app.db import get_session | ||
from app.models.overlays import Overlay, OverlayCreate | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get('/', response_model=list[Overlay]) | ||
async def get_overlays(session: AsyncSession = Depends(get_session)): | ||
result = await session.exec(select(Overlay)) | ||
overlays = result.all() | ||
return [Overlay(id=overlay.id, riot_id=overlay.riot_id, hdev_api_key=overlay.hdev_api_key) for overlay in overlays] | ||
|
||
@router.get("/{overlay_id}") | ||
async def get_overlay(overlay_id: uuid.UUID, session: AsyncSession = Depends(get_session)): | ||
statement = select(Overlay).where(Overlay.id == overlay_id) | ||
result = await session.exec(statement) | ||
overlay = result.first() | ||
|
||
if overlay is None: | ||
raise HTTPException(status_code=404, detail="Overlay not found") | ||
|
||
return overlay | ||
|
||
|
||
@router.post("/") | ||
async def create_overlay(overlay: OverlayCreate, session: AsyncSession = Depends(get_session)): | ||
overlay = Overlay(riot_id=overlay.riot_id, hdev_api_key=overlay.hdev_api_key) | ||
session.add(overlay) | ||
await session.commit() | ||
await session.refresh(overlay) | ||
return overlay |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
import secrets | ||
from os import environ | ||
from typing import Literal | ||
|
||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
from pathlib import Path | ||
from dotenv import load_dotenv | ||
|
||
|
||
def str_to_bool(value: str) -> bool: | ||
return value.lower() in ("true", "1", "yes") | ||
|
||
BASE_DIR: Path = Path(__file__).resolve().parent.parent.parent | ||
|
||
class Settings(BaseSettings): | ||
model_config = SettingsConfigDict( | ||
env_file="../.env", | ||
env_ignore_empty=True, | ||
extra="ignore", | ||
) | ||
API_V1_STR: str = "/api/v1" | ||
SECRET_KEY: str = secrets.token_urlsafe(32) | ||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 | ||
FRONTEND_HOST: str = "http://localhost:5173" | ||
ENVIRONMENT: Literal["local", "staging", "production"] = "local" | ||
|
||
PROJECT_NAME: str = environ.get("PROJECT_NAME") | ||
dotenv_file: Path = BASE_DIR / ".env" | ||
if dotenv_file.is_file(): | ||
load_dotenv(dotenv_file) | ||
|
||
DEBUG: bool = str_to_bool(environ.get("DEBUG", "False")) | ||
PROJECT_NAME: str = environ.get("PROJECT_NAME") | ||
|
||
PROJECT_NAME: str = environ.get("PROJECT_NAME") | ||
VERSION: str = environ.get("VERSION") | ||
DEBUG: bool = str_to_bool(environ.get("DEBUG", "False")) | ||
|
||
DATABASE_URL: str = environ.get("DATABASE_URL") | ||
DEBUG_DATABASE_URL: str = environ.get("DEBUG_DATABASE_URL") | ||
PROJECT_NAME: str = environ.get("PROJECT_NAME") | ||
VERSION: str = environ.get("VERSION") | ||
|
||
DATABASE_LOGIN: str = environ.get("DATABASE_LOGIN") | ||
DATABASE_PASSWORD: str = environ.get("DATABASE_PASSWORD") | ||
DATABASE_NAME: str = environ.get("DATABASE_NAME") | ||
DATABASE_PORT: int = int(environ.get("DATABASE_PORT", 5432)) | ||
|
||
settings = Settings() | ||
DATABASE_URL: str = f"postgresql+asyncpg://{DATABASE_LOGIN}:{DATABASE_PASSWORD}@localhost:{DATABASE_PORT}/{DATABASE_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.