from fastapi import Depends, FastAPI from . import crud, schemas from .database import create_db, engine, get_session # FIXME: # В проде добавить CORS, который будет обслуживать фронт. app = FastAPI(title="Demo FastAPI + React") # Создаю таблицы при запуске @app.on_event("startup") async def on_startup(): await create_db(engine) # Получение предметов через GET @app.get("/api/items", response_model=list[schemas.ItemRead]) async def read_items( session=Depends(get_session), ): return await crud.list_items(session) # Добавление предметов через POST @app.post("/api/items", response_model=schemas.ItemRead) async def create_item( item: schemas.ItemCreate, session=Depends(get_session) ): return await crud.create_item(session, item)