-
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
13 changed files
with
99 additions
and
77 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from fastapi import APIRouter | ||
from app.api.api_v1.endpoints import overlay | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(overlay.router, prefix="/overlay", tags=["overlay"]) |
Empty file.
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,30 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy.orm import Session | ||
from app.schemas.user import UserCreate | ||
from app.crud.user import create_user | ||
from app.db.session import get_db | ||
|
||
router = APIRouter() | ||
|
||
@router.get("/", response_model=list[Overlay]) | ||
async def get_overlays(session: AsyncSession = Depends(get_db)): | ||
result = await session.execute(select(Overlay)) | ||
overlays = result.scalars().all() | ||
return [Overlay(riotId=overlay.riotId, hdevApiKey=overlay.hdevApiKey, uuid=overlay.uuid) for overlay in overlays] | ||
|
||
@router.get("/{overlay_id}", response_model=OverlaySchema) | ||
async def get_overlay(overlay_id: str, session: AsyncSession = Depends(get_db)): | ||
result = await session.execute(select(Overlay).filter(Overlay.uuid == overlay_id)) | ||
overlay = result.scalars().first() | ||
if overlay is None: | ||
raise HTTPException(status_code=404, detail="Overlay not found") | ||
return overlay | ||
|
||
@router.post("/") | ||
async def add_overlay(overlay: OverlayCreate, session: AsyncSession = Depends(get_db)): | ||
overlay = Overlay(riotId=overlay.riotId, hdevApiKey=overlay.hdevApiKey) | ||
session.add(overlay) | ||
await session.commit() | ||
await session.refresh(overlay) | ||
return overlay |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
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,3 @@ | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
Base = declarative_base() |
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, AsyncSession | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlmodel import SQLModel | ||
|
||
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/valory" | ||
engine = create_async_engine(DATABASE_URL, echo=True, future=True) | ||
|
||
AsyncSessionLocal = sessionmaker( | ||
bind=engine, | ||
class_=AsyncSession, | ||
expire_on_commit=False, | ||
) | ||
|
||
async def get_db() -> AsyncSession: | ||
async with AsyncSessionLocal() as session: | ||
yield session | ||
|
||
async def init_db(): | ||
async with engine.begin() as conn: | ||
await conn.run_sync(SQLModel.metadata.create_all) |
This file was deleted.
Oops, something went wrong.
Empty file.
File renamed without changes.
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 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,37 @@ | ||
from contextlib import asynccontextmanager | ||
|
||
from fastapi import FastAPI, Depends, HTTPException | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
from sqlmodel import select | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from Valory.backend.app import settings | ||
from Valory.backend.app.api import api_router | ||
|
||
@asynccontextmanager | ||
async def lifespan(app: FastAPI): | ||
# Выполняется при старте приложения | ||
await init_db() | ||
print("Application startup complete.") | ||
|
||
yield # Контроль передается приложению | ||
|
||
# Выполняется при завершении работы приложения | ||
print("Application shutdown complete.") | ||
|
||
app = FastAPI( | ||
title=settings.PROJECT_NAME, | ||
version=settings.VERSION, | ||
lifespan=lifespan | ||
) | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router(api_router, prefix="/api/v1") |