ohmyapi 0.1.25__tar.gz → 0.1.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/PKG-INFO +16 -11
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/README.md +9 -7
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/pyproject.toml +4 -4
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/auth/routes.py +2 -2
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/demo/routes.py +9 -9
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/app/routes.py.j2 +4 -4
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/db/model/model.py +5 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/__main__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/auth/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/auth/models.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/auth/permissions.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/demo/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/builtin/demo/models.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/cli.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/runtime.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/scaffolding.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/app/__init__.py.j2 +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/app/models.py.j2 +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/project/README.md.j2 +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/project/pyproject.toml.j2 +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/core/templates/project/settings.py.j2 +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/db/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/db/exceptions.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/db/model/__init__.py +0 -0
- {ohmyapi-0.1.25 → ohmyapi-0.1.26}/src/ohmyapi/router.py +0 -0
@@ -1,13 +1,16 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ohmyapi
|
3
|
-
Version: 0.1.
|
4
|
-
Summary:
|
3
|
+
Version: 0.1.26
|
4
|
+
Summary: Django-flavored scaffolding and management layer around FastAPI, Pydantic, TortoiseORM and Aerich migrations
|
5
5
|
License-Expression: MIT
|
6
|
-
Keywords: fastapi,tortoise,orm,async,web-framework
|
6
|
+
Keywords: fastapi,tortoise,orm,pydantic,async,web-framework
|
7
7
|
Author: Brian Wiborg
|
8
8
|
Author-email: me@brianwib.org
|
9
|
-
Requires-Python: >=3.
|
9
|
+
Requires-Python: >=3.10
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
11
14
|
Classifier: Programming Language :: Python :: 3.13
|
12
15
|
Classifier: Programming Language :: Python :: 3.14
|
13
16
|
Provides-Extra: auth
|
@@ -157,6 +160,8 @@ Next, create your endpoints in `tournament/routes.py`:
|
|
157
160
|
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
158
161
|
from ohmyapi.db.exceptions import DoesNotExist
|
159
162
|
|
163
|
+
from typing import List
|
164
|
+
|
160
165
|
from .models import Tournament
|
161
166
|
|
162
167
|
# OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
|
@@ -169,23 +174,23 @@ from .models import Tournament
|
|
169
174
|
tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
170
175
|
|
171
176
|
|
172
|
-
@tournament_router.get("/")
|
177
|
+
@tournament_router.get("/", response_model=List[Tournament.Schema()])
|
173
178
|
async def list():
|
174
179
|
queryset = Tournament.all()
|
175
180
|
return await Tournament.Schema.model.from_queryset(queryset)
|
176
181
|
|
177
182
|
|
178
183
|
@tournament_router.post("/", status_code=HTTPStatus.CREATED)
|
179
|
-
async def post(tournament: Tournament.Schema
|
184
|
+
async def post(tournament: Tournament.Schema(readonly=True)):
|
180
185
|
queryset = Tournament.create(**payload.model_dump())
|
181
|
-
return await Tournament.Schema.
|
186
|
+
return await Tournament.Schema().from_queryset(queryset)
|
182
187
|
|
183
188
|
|
184
|
-
@tournament_router.get("/:id")
|
189
|
+
@tournament_router.get("/:id", response_model=Tournament.Schema())
|
185
190
|
async def get(id: str):
|
186
191
|
try:
|
187
192
|
queryset = Tournament.get(id=id)
|
188
|
-
return await Tournament.Schema.
|
193
|
+
return await Tournament.Schema().from_queryset_single(tournament)
|
189
194
|
except DoesNotExist:
|
190
195
|
raise HTTPException(status_code=404, detail="not found")
|
191
196
|
|
@@ -305,7 +310,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
305
310
|
@router.get("/")
|
306
311
|
async def list(user: auth.User = Depends(permissions.require_authenticated)):
|
307
312
|
queryset = Tournament.all()
|
308
|
-
return await Tournament.Schema.
|
313
|
+
return await Tournament.Schema().from_queryset(queryset)
|
309
314
|
|
310
315
|
|
311
316
|
...
|
@@ -347,7 +352,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
347
352
|
@router.get("/teams")
|
348
353
|
async def teams(user: auth.User = Depends(permissions.require_authenticated)):
|
349
354
|
queryset = Team.for_user(user)
|
350
|
-
return await Tournament.Schema.
|
355
|
+
return await Tournament.Schema().from_queryset(queryset)
|
351
356
|
```
|
352
357
|
|
353
358
|
## Shell
|
@@ -125,6 +125,8 @@ Next, create your endpoints in `tournament/routes.py`:
|
|
125
125
|
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
126
126
|
from ohmyapi.db.exceptions import DoesNotExist
|
127
127
|
|
128
|
+
from typing import List
|
129
|
+
|
128
130
|
from .models import Tournament
|
129
131
|
|
130
132
|
# OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
|
@@ -137,23 +139,23 @@ from .models import Tournament
|
|
137
139
|
tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
138
140
|
|
139
141
|
|
140
|
-
@tournament_router.get("/")
|
142
|
+
@tournament_router.get("/", response_model=List[Tournament.Schema()])
|
141
143
|
async def list():
|
142
144
|
queryset = Tournament.all()
|
143
145
|
return await Tournament.Schema.model.from_queryset(queryset)
|
144
146
|
|
145
147
|
|
146
148
|
@tournament_router.post("/", status_code=HTTPStatus.CREATED)
|
147
|
-
async def post(tournament: Tournament.Schema
|
149
|
+
async def post(tournament: Tournament.Schema(readonly=True)):
|
148
150
|
queryset = Tournament.create(**payload.model_dump())
|
149
|
-
return await Tournament.Schema.
|
151
|
+
return await Tournament.Schema().from_queryset(queryset)
|
150
152
|
|
151
153
|
|
152
|
-
@tournament_router.get("/:id")
|
154
|
+
@tournament_router.get("/:id", response_model=Tournament.Schema())
|
153
155
|
async def get(id: str):
|
154
156
|
try:
|
155
157
|
queryset = Tournament.get(id=id)
|
156
|
-
return await Tournament.Schema.
|
158
|
+
return await Tournament.Schema().from_queryset_single(tournament)
|
157
159
|
except DoesNotExist:
|
158
160
|
raise HTTPException(status_code=404, detail="not found")
|
159
161
|
|
@@ -273,7 +275,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
273
275
|
@router.get("/")
|
274
276
|
async def list(user: auth.User = Depends(permissions.require_authenticated)):
|
275
277
|
queryset = Tournament.all()
|
276
|
-
return await Tournament.Schema.
|
278
|
+
return await Tournament.Schema().from_queryset(queryset)
|
277
279
|
|
278
280
|
|
279
281
|
...
|
@@ -315,7 +317,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
315
317
|
@router.get("/teams")
|
316
318
|
async def teams(user: auth.User = Depends(permissions.require_authenticated)):
|
317
319
|
queryset = Team.for_user(user)
|
318
|
-
return await Tournament.Schema.
|
320
|
+
return await Tournament.Schema().from_queryset(queryset)
|
319
321
|
```
|
320
322
|
|
321
323
|
## Shell
|
@@ -1,14 +1,14 @@
|
|
1
1
|
[project]
|
2
2
|
name = "ohmyapi"
|
3
|
-
version = "0.1.
|
4
|
-
description = "
|
3
|
+
version = "0.1.26"
|
4
|
+
description = "Django-flavored scaffolding and management layer around FastAPI, Pydantic, TortoiseORM and Aerich migrations"
|
5
5
|
license = "MIT"
|
6
|
-
keywords = ["fastapi", "tortoise", "orm", "async", "web-framework"]
|
6
|
+
keywords = ["fastapi", "tortoise", "orm", "pydantic", "async", "web-framework"]
|
7
7
|
authors = [
|
8
8
|
{name = "Brian Wiborg", email = "me@brianwib.org"}
|
9
9
|
]
|
10
10
|
readme = "README.md"
|
11
|
-
requires-python = ">=3.
|
11
|
+
requires-python = ">=3.10"
|
12
12
|
|
13
13
|
dependencies = [
|
14
14
|
"typer >=0.19.1,<0.20.0",
|
@@ -207,7 +207,7 @@ async def introspect(token: Dict = Depends(get_token)):
|
|
207
207
|
return token
|
208
208
|
|
209
209
|
|
210
|
-
@router.get("/me", response_model=User.Schema
|
210
|
+
@router.get("/me", response_model=User.Schema())
|
211
211
|
async def me(user: User = Depends(get_current_user)):
|
212
212
|
"""Return the currently authenticated user."""
|
213
|
-
return await User.Schema.
|
213
|
+
return await User.Schema().from_tortoise_orm(user)
|
@@ -8,29 +8,29 @@ from typing import List
|
|
8
8
|
# Expose your app's routes via `router = fastapi.APIRouter`.
|
9
9
|
# Use prefixes wisely to avoid cross-app namespace-collisions.
|
10
10
|
# Tags improve the UX of the OpenAPI docs at /docs.
|
11
|
-
router = APIRouter(prefix="/
|
11
|
+
router = APIRouter(prefix="/tournament")
|
12
12
|
|
13
13
|
|
14
14
|
@router.get(
|
15
|
-
"/", tags=["tournament"], response_model=List[models.Tournament.Schema
|
15
|
+
"/", tags=["tournament"], response_model=List[models.Tournament.Schema()]
|
16
16
|
)
|
17
17
|
async def list():
|
18
18
|
"""List all tournaments."""
|
19
|
-
return await models.Tournament.Schema.
|
19
|
+
return await models.Tournament.Schema().from_queryset(models.Tournament.all())
|
20
20
|
|
21
21
|
|
22
22
|
@router.post("/", tags=["tournament"], status_code=HTTPStatus.CREATED)
|
23
|
-
async def post(tournament: models.Tournament.Schema
|
23
|
+
async def post(tournament: models.Tournament.Schema(readonly=True)):
|
24
24
|
"""Create tournament."""
|
25
|
-
return await models.Tournament.Schema.
|
25
|
+
return await models.Tournament.Schema().from_queryset(
|
26
26
|
models.Tournament.create(**tournament.model_dump())
|
27
27
|
)
|
28
28
|
|
29
29
|
|
30
|
-
@router.get("/{id}", tags=["tournament"], response_model=models.Tournament.Schema
|
30
|
+
@router.get("/{id}", tags=["tournament"], response_model=models.Tournament.Schema())
|
31
31
|
async def get(id: str):
|
32
32
|
"""Get tournament by id."""
|
33
|
-
return await models.Tournament.Schema.
|
33
|
+
return await models.Tournament.Schema().from_queryset(
|
34
34
|
models.Tournament.get(id=id)
|
35
35
|
)
|
36
36
|
|
@@ -43,12 +43,12 @@ async def get(id: str):
|
|
43
43
|
)
|
44
44
|
async def put(tournament: models.Tournament.Schema.model):
|
45
45
|
"""Update tournament."""
|
46
|
-
return await models.Tournament.Schema.
|
46
|
+
return await models.Tournament.Schema().from_queryset(
|
47
47
|
models.Tournament.update(**tournament.model_dump())
|
48
48
|
)
|
49
49
|
|
50
50
|
|
51
|
-
@router.delete("/{id}", tags=["tournament"])
|
51
|
+
@router.delete("/{id}", status_code=HTTPStatus.ACCEPTED, tags=["tournament"])
|
52
52
|
async def delete(id: str):
|
53
53
|
try:
|
54
54
|
tournament = await models.Tournament.get(id=id)
|
@@ -14,16 +14,16 @@ from typing import List
|
|
14
14
|
router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}'])
|
15
15
|
|
16
16
|
|
17
|
-
@router.get("/")
|
17
|
+
@router.get("/", response_model=List)
|
18
18
|
async def list():
|
19
19
|
"""List all ..."""
|
20
20
|
return []
|
21
21
|
|
22
22
|
|
23
|
-
@router.post("/")
|
23
|
+
@router.post("/", status_code=HTTPStatus.CREATED)
|
24
24
|
async def post():
|
25
25
|
"""Create ..."""
|
26
|
-
|
26
|
+
raise HTTPException(status_code=HTTPStatus.IM_A_TEAPOT)
|
27
27
|
|
28
28
|
|
29
29
|
@router.get("/{id}")
|
@@ -38,7 +38,7 @@ async def put(id: str):
|
|
38
38
|
return HTTPException(status_code=HTTPStatus.ACCEPTED)
|
39
39
|
|
40
40
|
|
41
|
-
@router.delete("/{id}")
|
41
|
+
@router.delete("/{id}", status_code=HTTPStatus.ACCEPTED)
|
42
42
|
async def delete(id: str):
|
43
43
|
return HTTPException(status_code=HTTPStatus.ACCEPTED)
|
44
44
|
|
@@ -36,6 +36,11 @@ class ModelMeta(type(TortoiseModel)):
|
|
36
36
|
schema_opts = getattr(new_cls, "Schema", None)
|
37
37
|
|
38
38
|
class BoundSchema:
|
39
|
+
def __call__(self, readonly: bool = False):
|
40
|
+
if readonly:
|
41
|
+
return self.readonly
|
42
|
+
return self.model
|
43
|
+
|
39
44
|
@property
|
40
45
|
def model(self):
|
41
46
|
"""Return a Pydantic model class for serializing results."""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|