📝 Reflect latest changes
This commit is contained in:
parent
e142489ed9
commit
1b830f7bd2
3 changed files with 35 additions and 14 deletions
29
README.md
29
README.md
|
|
@ -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")
|
||||
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue