📝 Reflect latest changes
This commit is contained in:
parent
111a65da85
commit
31dd3a9e37
1 changed files with 66 additions and 23 deletions
89
README.md
89
README.md
|
|
@ -125,7 +125,7 @@ class Team(Model):
|
|||
Next, create your endpoints in `tournament/routes.py`:
|
||||
|
||||
```python
|
||||
from ohmyapi.router import APIRouter, HTTPException
|
||||
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
||||
from ohmyapi.db.exceptions import DoesNotExist
|
||||
|
||||
from .models import Tournament
|
||||
|
|
@ -135,20 +135,25 @@ from .models import Tournament
|
|||
# Tags improve the UX of the OpenAPI docs at /docs.
|
||||
router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def list():
|
||||
queryset = Tournament.all()
|
||||
return await Tournament.Schema.model.from_queryset(queryset)
|
||||
|
||||
|
||||
@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")
|
||||
async def get(id: str):
|
||||
try:
|
||||
tournament = await Tournament.get(pk=id)
|
||||
queryset = Tournament.get(id=id)
|
||||
return await Tournament.Schema.model.from_queryset_single(tournament)
|
||||
except DoesNotExist:
|
||||
raise HTTPException(status_code=404, detail="item not found")
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
|
||||
...
|
||||
```
|
||||
|
|
@ -318,27 +323,65 @@ Find your loaded project singleton via identifier: `p`
|
|||
|
||||
```python
|
||||
In [1]: p
|
||||
Out[1]: <ohmyapi.core.runtime.Project at 0xdeadbeefc0febabe>
|
||||
Out[1]: <ohmyapi.core.runtime.Project at 0x7f00c43dbcb0>
|
||||
|
||||
In [2]: p.apps
|
||||
Out[2]:
|
||||
{'ohmyapi_auth': App: ohmyapi_auth
|
||||
Models:
|
||||
- Group
|
||||
- User
|
||||
Routes:
|
||||
- APIRoute(path='/auth/login', name='login', methods=['POST'])
|
||||
- APIRoute(path='/auth/refresh', name='refresh_token', methods=['POST'])
|
||||
- APIRoute(path='/auth/introspect', name='introspect', methods=['GET'])
|
||||
- APIRoute(path='/auth/me', name='me', methods=['GET']),
|
||||
'tournament': App: tournament
|
||||
Models:
|
||||
- Tournament
|
||||
- Event
|
||||
- Team
|
||||
Routes:
|
||||
- APIRoute(path='/tournament/', name='list', methods=['GET'])}
|
||||
|
||||
In [3]: from tournament.models import Tournament
|
||||
{'ohmyapi_auth': {
|
||||
"models": [
|
||||
"Group",
|
||||
"User"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"path": "/auth/login",
|
||||
"name": "login",
|
||||
"methods": [
|
||||
"POST"
|
||||
],
|
||||
"endpoint": "login",
|
||||
"response_model": null,
|
||||
"tags": [
|
||||
"auth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/auth/refresh",
|
||||
"name": "refresh_token",
|
||||
"methods": [
|
||||
"POST"
|
||||
],
|
||||
"endpoint": "refresh_token",
|
||||
"response_model": null,
|
||||
"tags": [
|
||||
"auth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/auth/introspect",
|
||||
"name": "introspect",
|
||||
"methods": [
|
||||
"GET"
|
||||
],
|
||||
"endpoint": "introspect",
|
||||
"response_model": null,
|
||||
"tags": [
|
||||
"auth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/auth/me",
|
||||
"name": "me",
|
||||
"methods": [
|
||||
"GET"
|
||||
],
|
||||
"endpoint": "me",
|
||||
"response_model": null,
|
||||
"tags": [
|
||||
"auth"
|
||||
]
|
||||
}
|
||||
]
|
||||
}}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue