Skip to content

Commit 02f57c5

Browse files
committed
feat: add more features
1 parent d09b230 commit 02f57c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+129
-3129
lines changed

LICENSE

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

README.md

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

backend/db.py

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

backend/main.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from fastapi import FastAPI, Depends, HTTPException
2+
from fastapi.middleware.cors import CORSMiddleware
3+
4+
from sqlmodel import select
5+
from sqlmodel.ext.asyncio.session import AsyncSession
6+
7+
from db import init_db, get_session
8+
from models import Overlay, OverlayCreate
9+
10+
from schemas import OverlaySchema
11+
12+
app = FastAPI()
13+
14+
app.add_middleware(
15+
CORSMiddleware,
16+
allow_origins=["http://localhost:5173"],
17+
allow_credentials=True,
18+
allow_methods=["*"],
19+
allow_headers=["*"],
20+
)
21+
22+
@app.on_event("startup")
23+
async def on_startup():
24+
await init_db()
25+
26+
@app.get("/")
27+
async def root():
28+
return {"message": "Hello World"}
29+
30+
@app.get("/overlays", response_model=list[Overlay])
31+
async def get_overlays(session: AsyncSession = Depends(get_session)):
32+
result = await session.execute(select(Overlay))
33+
overlays = result.scalars().all()
34+
return [Overlay(nickname=overlay.nickname, tag=overlay.tag, uuid=overlay.uuid) for overlay in overlays]
35+
36+
@app.get("/overlay/{overlay_id}", response_model=OverlaySchema)
37+
async def get_overlay(overlay_id: str, session: AsyncSession = Depends(get_session)):
38+
result = await session.execute(select(Overlay).filter(Overlay.uuid == overlay_id))
39+
overlay = result.scalars().first()
40+
if overlay is None:
41+
raise HTTPException(status_code=404, detail="Overlay not found")
42+
return overlay
43+
44+
@app.post("/overlay")
45+
async def add_overlay(overlay: OverlayCreate, session: AsyncSession = Depends(get_session)):
46+
overlay = Overlay(nickname=overlay.nickname, tag=overlay.tag)
47+
session.add(overlay)
48+
await session.commit()
49+
await session.refresh(overlay)
50+
return overlay

backend/models.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from sqlmodel import SQLModel, Field
2+
import uuid as uuid_pkg
3+
4+
5+
class OverlayBase(SQLModel):
6+
nickname: str
7+
tag: str
8+
# hdevKey: str
9+
# textColor: str
10+
# primaryColor: str
11+
# bgColor: str
12+
# progressRankColor: str
13+
# progressRankBgColor: str
14+
# alphaBg: bool
15+
# alphaGradBg: bool
16+
# wlStat: bool
17+
# progressRank: bool
18+
# lastMatchPoints: bool
19+
20+
21+
class Overlay(OverlayBase, table=True):
22+
uuid: uuid_pkg.UUID = Field(
23+
default_factory=uuid_pkg.uuid4,
24+
primary_key=True,
25+
index=True,
26+
nullable=False,
27+
)
28+
29+
30+
class OverlayCreate(OverlayBase):
31+
pass

backend/schemas.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from uuid import UUID
2+
3+
from pydantic import BaseModel
4+
5+
class OverlaySchema(BaseModel):
6+
uuid: UUID
7+
nickname: str
8+
tag: str
9+
10+
class Config:
11+
orm_mode = True # Включает поддержку ORM для SQLAlchemy моделей

backend/settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ast
2+
from os import environ
3+
from pathlib import Path
4+
5+
from dotenv import load_dotenv
6+
7+
BASE_DIR = Path(__file__).resolve().parent.parent.parent
8+
9+
dotenv_file = BASE_DIR / '.env'
10+
if dotenv_file.is_file():
11+
load_dotenv(dotenv_file)
12+
13+
DEBUG = ast.literal_eval(environ.get('DEBUG'))
File renamed without changes.
File renamed without changes.

index.html

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

0 commit comments

Comments
 (0)