init codebase

This commit is contained in:
grillazz
2021-03-26 11:07:52 +01:00
parent 5e9e294b27
commit d7e0db47e5
21 changed files with 367 additions and 1 deletions

0
the_app/api/__init__.py Normal file
View File

39
the_app/api/stuff.py Normal file
View 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)