mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
add json filed example
This commit is contained in:
@@ -4,14 +4,23 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.stuff import Stuff
|
||||
from app.schemas.stuff import StuffResponse, StuffSchema
|
||||
from app.models.stuff import Stuff, RandomStuff
|
||||
from app.schemas.stuff import StuffResponse, StuffSchema, RandomStuff as RandomStuffSchema
|
||||
|
||||
logger = AppStructLogger().get_logger()
|
||||
|
||||
router = APIRouter(prefix="/v1/stuff")
|
||||
|
||||
|
||||
@router.post("/random", status_code=status.HTTP_201_CREATED)
|
||||
async def create_random_stuff(
|
||||
payload: RandomStuffSchema, db_session: AsyncSession = Depends(get_db)
|
||||
) -> dict[str, str]:
|
||||
random_stuff = RandomStuff(**payload.model_dump())
|
||||
await random_stuff.save(db_session)
|
||||
return {"id": str(random_stuff.id)}
|
||||
|
||||
|
||||
@router.post("/add_many", status_code=status.HTTP_201_CREATED)
|
||||
async def create_multi_stuff(
|
||||
payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)
|
||||
|
||||
Reference in New Issue
Block a user