📝 Reflect latest changes

This commit is contained in:
Brian Wiborg 2025-09-29 17:17:54 +02:00
parent e142489ed9
commit 1b830f7bd2
No known key found for this signature in database
3 changed files with 35 additions and 14 deletions

View file

@ -30,7 +30,7 @@ It is ***blazingly fast***, extremely ***fun to use*** and comes with ***batteri
**Creating a Project**
```
pip install ohmyapi
pipx install ohmyapi
ohmyapi startproject myproject
cd myproject
```
@ -127,24 +127,29 @@ from ohmyapi.db.exceptions import DoesNotExist
from .models import Tournament
# Expose your app's routes via `router = fastapi.APIRouter`.
# Use prefixes wisely to avoid cross-app namespace-collisions.
# OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
# add their routes to the main project router.
#
# Note:
# Use prefixes wisely to avoid cross-app namespace-collisions!
# Tags improve the UX of the OpenAPI docs at /docs.
router = APIRouter(prefix="/tournament", tags=['Tournament'])
#
tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
@router.get("/")
@tournament_router.get("/")
async def list():
queryset = Tournament.all()
return await Tournament.Schema.model.from_queryset(queryset)
@router.post("/", status_code=HTTPStatus.CREATED)
@tournament_router.post("/", status_code=HTTPStatus.CREATED)
async def post(tournament: Tournament.Schema.readonly):
queryset = Tournament.create(**payload.model_dump())
return await Tournament.Schema.model.from_queryset(queryset)
@router.get("/:id")
@tournament_router.get("/:id")
async def get(id: str):
try:
queryset = Tournament.get(id=id)
@ -152,6 +157,16 @@ async def get(id: str):
except DoesNotExist:
raise HTTPException(status_code=404, detail="not found")
@tournament_router.delete("/:id")
async def delete(id: str):
try:
tournament = await Tournament.get(id=id)
return await Tournament.Schema.model.from_queryset(tournament.delete())
except DoesNotExist:
raise HTTPException(status_code=404, detail="not found")
...
```