ohmyapi 0.1.25__py3-none-any.whl → 0.1.27__py3-none-any.whl
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/builtin/auth/routes.py +2 -2
- ohmyapi/builtin/demo/routes.py +9 -9
- ohmyapi/core/runtime.py +4 -12
- ohmyapi/core/templates/app/routes.py.j2 +4 -4
- ohmyapi/db/model/model.py +5 -0
- {ohmyapi-0.1.25.dist-info → ohmyapi-0.1.27.dist-info}/METADATA +15 -11
- {ohmyapi-0.1.25.dist-info → ohmyapi-0.1.27.dist-info}/RECORD +9 -9
- {ohmyapi-0.1.25.dist-info → ohmyapi-0.1.27.dist-info}/WHEEL +0 -0
- {ohmyapi-0.1.25.dist-info → ohmyapi-0.1.27.dist-info}/entry_points.txt +0 -0
ohmyapi/builtin/auth/routes.py
CHANGED
@@ -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)
|
ohmyapi/builtin/demo/routes.py
CHANGED
@@ -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)
|
ohmyapi/core/runtime.py
CHANGED
@@ -119,26 +119,18 @@ class Project:
|
|
119
119
|
def build_aerich_command(
|
120
120
|
self, app_label: str, db_url: Optional[str] = None
|
121
121
|
) -> AerichCommand:
|
122
|
-
|
123
|
-
|
124
|
-
flat_label = app_label
|
125
|
-
else:
|
126
|
-
candidate = app_label.replace(".", "_")
|
127
|
-
if candidate in self._apps:
|
128
|
-
flat_label = candidate
|
129
|
-
else:
|
130
|
-
raise RuntimeError(f"App '{app_label}' is not registered")
|
122
|
+
if app_label not in self._apps:
|
123
|
+
raise RuntimeError(f"App '{app_label}' is not registered")
|
131
124
|
|
132
125
|
# Get a fresh copy of the config (without aerich.models anywhere)
|
133
126
|
tortoise_cfg = copy.deepcopy(self.build_tortoise_config(db_url=db_url))
|
134
127
|
|
135
128
|
# Append aerich.models to the models list of the target app only
|
136
|
-
|
137
|
-
tortoise_cfg["apps"][flat_label]["models"].append("aerich.models")
|
129
|
+
tortoise_cfg["apps"][app_label]["models"].append("aerich.models")
|
138
130
|
|
139
131
|
return AerichCommand(
|
140
132
|
tortoise_config=tortoise_cfg,
|
141
|
-
app=
|
133
|
+
app=app_label,
|
142
134
|
location=str(self.migrations_dir),
|
143
135
|
)
|
144
136
|
|
@@ -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
|
|
ohmyapi/db/model/model.py
CHANGED
@@ -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."""
|
@@ -1,13 +1,15 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ohmyapi
|
3
|
-
Version: 0.1.
|
4
|
-
Summary:
|
3
|
+
Version: 0.1.27
|
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.11
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
11
13
|
Classifier: Programming Language :: Python :: 3.13
|
12
14
|
Classifier: Programming Language :: Python :: 3.14
|
13
15
|
Provides-Extra: auth
|
@@ -157,6 +159,8 @@ Next, create your endpoints in `tournament/routes.py`:
|
|
157
159
|
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
158
160
|
from ohmyapi.db.exceptions import DoesNotExist
|
159
161
|
|
162
|
+
from typing import List
|
163
|
+
|
160
164
|
from .models import Tournament
|
161
165
|
|
162
166
|
# OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
|
@@ -169,23 +173,23 @@ from .models import Tournament
|
|
169
173
|
tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
170
174
|
|
171
175
|
|
172
|
-
@tournament_router.get("/")
|
176
|
+
@tournament_router.get("/", response_model=List[Tournament.Schema()])
|
173
177
|
async def list():
|
174
178
|
queryset = Tournament.all()
|
175
179
|
return await Tournament.Schema.model.from_queryset(queryset)
|
176
180
|
|
177
181
|
|
178
182
|
@tournament_router.post("/", status_code=HTTPStatus.CREATED)
|
179
|
-
async def post(tournament: Tournament.Schema
|
183
|
+
async def post(tournament: Tournament.Schema(readonly=True)):
|
180
184
|
queryset = Tournament.create(**payload.model_dump())
|
181
|
-
return await Tournament.Schema.
|
185
|
+
return await Tournament.Schema().from_queryset(queryset)
|
182
186
|
|
183
187
|
|
184
|
-
@tournament_router.get("/:id")
|
188
|
+
@tournament_router.get("/:id", response_model=Tournament.Schema())
|
185
189
|
async def get(id: str):
|
186
190
|
try:
|
187
191
|
queryset = Tournament.get(id=id)
|
188
|
-
return await Tournament.Schema.
|
192
|
+
return await Tournament.Schema().from_queryset_single(tournament)
|
189
193
|
except DoesNotExist:
|
190
194
|
raise HTTPException(status_code=404, detail="not found")
|
191
195
|
|
@@ -305,7 +309,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
305
309
|
@router.get("/")
|
306
310
|
async def list(user: auth.User = Depends(permissions.require_authenticated)):
|
307
311
|
queryset = Tournament.all()
|
308
|
-
return await Tournament.Schema.
|
312
|
+
return await Tournament.Schema().from_queryset(queryset)
|
309
313
|
|
310
314
|
|
311
315
|
...
|
@@ -347,7 +351,7 @@ router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
|
347
351
|
@router.get("/teams")
|
348
352
|
async def teams(user: auth.User = Depends(permissions.require_authenticated)):
|
349
353
|
queryset = Team.for_user(user)
|
350
|
-
return await Tournament.Schema.
|
354
|
+
return await Tournament.Schema().from_queryset(queryset)
|
351
355
|
```
|
352
356
|
|
353
357
|
## Shell
|
@@ -3,26 +3,26 @@ ohmyapi/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
|
|
3
3
|
ohmyapi/builtin/auth/__init__.py,sha256=vOVCSJX8BALzs8h5ZW9507bjoscP37bncMjdMmBXcMM,42
|
4
4
|
ohmyapi/builtin/auth/models.py,sha256=Fggg3GDVydKoZQOlXXNDsWKxehvsp8BXC1xedv0Qr34,1729
|
5
5
|
ohmyapi/builtin/auth/permissions.py,sha256=mxsnhF_UGesTFle7v1JHORkNODtQ0qanAL3FtOcMCEY,145
|
6
|
-
ohmyapi/builtin/auth/routes.py,sha256=
|
6
|
+
ohmyapi/builtin/auth/routes.py,sha256=ZNtGUZahmUboTNT_LB2F9sbjpSPp86DtgkOOj73mKlc,6304
|
7
7
|
ohmyapi/builtin/demo/__init__.py,sha256=k1rGtOmMPVZJ1fMPELY0v3k70WyzSp18pstJTkCdFr0,42
|
8
8
|
ohmyapi/builtin/demo/models.py,sha256=N3LnHLEa5wYBvaQBImCR4SdZvRYGuwM_iyLCeh9QY8s,1403
|
9
|
-
ohmyapi/builtin/demo/routes.py,sha256=
|
9
|
+
ohmyapi/builtin/demo/routes.py,sha256=JZbW_ZBirzNEO6PuJO_ZPV4k__cH8rvU9JN6CDhocWc,1821
|
10
10
|
ohmyapi/cli.py,sha256=dJVNgpW5S4rCc619AEEKBKuEIAmQs153Ls0ZVaea48w,4173
|
11
11
|
ohmyapi/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
ohmyapi/core/runtime.py,sha256=
|
12
|
+
ohmyapi/core/runtime.py,sha256=tdFSOu9fV2BjcE5BIfGfm3jjeGw6Tw8jCM6-hk5Be2s,9264
|
13
13
|
ohmyapi/core/scaffolding.py,sha256=SA0SYFd7VcqkOn9xuXgj-yOoVqCZMJo68GGFbm34GE4,2663
|
14
14
|
ohmyapi/core/templates/app/__init__.py.j2,sha256=QwVIQVUGZVhdH1d4NrvL7NTsK4-T4cihzYs8UVX2dt4,43
|
15
15
|
ohmyapi/core/templates/app/models.py.j2,sha256=_3w-vFJ5fgsmncsCv34k_wyCMF78jufbSSglns4gbb0,119
|
16
|
-
ohmyapi/core/templates/app/routes.py.j2,sha256=
|
16
|
+
ohmyapi/core/templates/app/routes.py.j2,sha256=SxLz_wvakusj5txbXToZyNq6ZmcamSwNjVrI0MNPRl0,1037
|
17
17
|
ohmyapi/core/templates/project/README.md.j2,sha256=SjR4JIrg-8XRE-UntUDwiw8jDpYitD_UjwoKkYJ7GLw,22
|
18
18
|
ohmyapi/core/templates/project/pyproject.toml.j2,sha256=3ZqO6FX9Bhq8OAZl8nHPXCiWxl3gAffIF-LsC_-K9Us,538
|
19
19
|
ohmyapi/core/templates/project/settings.py.j2,sha256=So6w1OiL_jU-FyeT8IHueDjGNuEoSkYhabhHpne2fUU,140
|
20
20
|
ohmyapi/db/__init__.py,sha256=5QKUycxnN83DOUD_Etoee9tEOYjnZ74deqrSOOx_MiQ,204
|
21
21
|
ohmyapi/db/exceptions.py,sha256=vb4IIUoeYAY6sK42zRtjMy-39IFVi_Qb6mWySTY0jYw,34
|
22
22
|
ohmyapi/db/model/__init__.py,sha256=k3StTNuKatpwZo_Z5JBFa-927eJrzibFE8U4SA82asc,32
|
23
|
-
ohmyapi/db/model/model.py,sha256=
|
23
|
+
ohmyapi/db/model/model.py,sha256=MQAXVDYpCjGFWfn3u2XP4Q6OZzIJrJBWOWcg5sBDhlw,2581
|
24
24
|
ohmyapi/router.py,sha256=6Exv6sVPVyiIYxxAQbxQhFRX74MKTUPWXIBwC7UZ-ww,82
|
25
|
-
ohmyapi-0.1.
|
26
|
-
ohmyapi-0.1.
|
27
|
-
ohmyapi-0.1.
|
28
|
-
ohmyapi-0.1.
|
25
|
+
ohmyapi-0.1.27.dist-info/METADATA,sha256=a9h8zsKsiutguUDcdzBZcWjxgwjBRBLbbMFGeW1n7k0,10281
|
26
|
+
ohmyapi-0.1.27.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
|
27
|
+
ohmyapi-0.1.27.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
|
28
|
+
ohmyapi-0.1.27.dist-info/RECORD,,
|
File without changes
|
File without changes
|