mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
init codebase
This commit is contained in:
0
the_app/api/__init__.py
Normal file
0
the_app/api/__init__.py
Normal file
39
the_app/api/stuff.py
Normal file
39
the_app/api/stuff.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from the_app.database import get_db
|
||||
from the_app.models.stuff import Stuff
|
||||
from the_app.schemas.stuff import StuffResponse, StuffSchema
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/", response_model=StuffResponse)
|
||||
async def create_stuff(stuff: StuffSchema, db_session: AsyncSession = Depends(get_db)):
|
||||
stuff_id = await Stuff.create(db_session, stuff)
|
||||
return {**stuff.dict(), "id": stuff_id}
|
||||
|
||||
|
||||
@router.delete("/")
|
||||
async def delete_stuff(stuff_id: UUID, db_session: AsyncSession = Depends(get_db)):
|
||||
return await Stuff.delete(db_session, stuff_id)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def find_stuff(
|
||||
name: str,
|
||||
db_session: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await Stuff.find(db_session, name)
|
||||
|
||||
|
||||
@router.patch("/")
|
||||
async def update_config(
|
||||
stuff: StuffSchema,
|
||||
name: str,
|
||||
db_session: AsyncSession = Depends(get_db),
|
||||
):
|
||||
instance_of_the_stuff = await Stuff.find(db_session, name)
|
||||
return instance_of_the_stuff.update(db_session, stuff)
|
||||
Reference in New Issue
Block a user