📝 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`:
|
Next, create your endpoints in `tournament/routes.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from ohmyapi.router import APIRouter, HTTPException
|
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
||||||
from ohmyapi.db.exceptions import DoesNotExist
|
from ohmyapi.db.exceptions import DoesNotExist
|
||||||
|
|
||||||
from .models import Tournament
|
from .models import Tournament
|
||||||
|
|
@ -135,20 +135,25 @@ from .models import Tournament
|
||||||
# Tags improve the UX of the OpenAPI docs at /docs.
|
# Tags improve the UX of the OpenAPI docs at /docs.
|
||||||
router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def list():
|
async def list():
|
||||||
queryset = Tournament.all()
|
queryset = Tournament.all()
|
||||||
return await Tournament.Schema.model.from_queryset(queryset)
|
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")
|
@router.get("/:id")
|
||||||
async def get(id: str):
|
async def get(id: str):
|
||||||
try:
|
try:
|
||||||
tournament = await Tournament.get(pk=id)
|
queryset = Tournament.get(id=id)
|
||||||
return await Tournament.Schema.model.from_queryset_single(tournament)
|
return await Tournament.Schema.model.from_queryset_single(tournament)
|
||||||
except DoesNotExist:
|
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
|
```python
|
||||||
In [1]: p
|
In [1]: p
|
||||||
Out[1]: <ohmyapi.core.runtime.Project at 0xdeadbeefc0febabe>
|
Out[1]: <ohmyapi.core.runtime.Project at 0x7f00c43dbcb0>
|
||||||
|
|
||||||
In [2]: p.apps
|
In [2]: p.apps
|
||||||
Out[2]:
|
Out[2]:
|
||||||
{'ohmyapi_auth': App: ohmyapi_auth
|
{'ohmyapi_auth': {
|
||||||
Models:
|
"models": [
|
||||||
- Group
|
"Group",
|
||||||
- User
|
"User"
|
||||||
Routes:
|
],
|
||||||
- APIRoute(path='/auth/login', name='login', methods=['POST'])
|
"routes": [
|
||||||
- APIRoute(path='/auth/refresh', name='refresh_token', methods=['POST'])
|
{
|
||||||
- APIRoute(path='/auth/introspect', name='introspect', methods=['GET'])
|
"path": "/auth/login",
|
||||||
- APIRoute(path='/auth/me', name='me', methods=['GET']),
|
"name": "login",
|
||||||
'tournament': App: tournament
|
"methods": [
|
||||||
Models:
|
"POST"
|
||||||
- Tournament
|
],
|
||||||
- Event
|
"endpoint": "login",
|
||||||
- Team
|
"response_model": null,
|
||||||
Routes:
|
"tags": [
|
||||||
- APIRoute(path='/tournament/', name='list', methods=['GET'])}
|
"auth"
|
||||||
|
]
|
||||||
In [3]: from tournament.models import Tournament
|
},
|
||||||
|
{
|
||||||
|
"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