ohmyapi 0.1.24__py3-none-any.whl → 0.1.25__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/core/runtime.py CHANGED
@@ -211,7 +211,7 @@ class App:
211
211
  self.model_modules: List[str] = []
212
212
 
213
213
  # The APIRouter
214
- self.router: Optional[APIRouter] = None
214
+ self.router: APIRouter = APIRouter()
215
215
 
216
216
  # Import the app, so its __init__.py runs.
217
217
  importlib.import_module(self.name)
@@ -226,9 +226,12 @@ class App:
226
226
  # Locate the APIRouter
227
227
  try:
228
228
  routes_mod = importlib.import_module(f"{self.name}.routes")
229
- router = getattr(routes_mod, "router", None)
230
- if isinstance(router, APIRouter):
231
- self.router = router
229
+ for attr_name in dir(routes_mod):
230
+ if attr_name.startswith("__"):
231
+ continue
232
+ attr = getattr(routes_mod, attr_name)
233
+ if isinstance(attr, APIRouter):
234
+ self.router.include_router(attr)
232
235
  except ModuleNotFoundError:
233
236
  pass
234
237
 
@@ -4,13 +4,16 @@ from . import models
4
4
 
5
5
  from typing import List
6
6
 
7
- # Expose your app's routes via `router = fastapi.APIRouter`.
8
- # Use prefixes wisely to avoid cross-app namespace-collisions.
7
+ # OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
8
+ # add their routes to the main project router.
9
+ #
10
+ # Note:
11
+ # Use prefixes wisely to avoid cross-app namespace-collisions!
9
12
  # Tags improve the UX of the OpenAPI docs at /docs.
13
+ #
10
14
  router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}'])
11
15
 
12
16
 
13
-
14
17
  @router.get("/")
15
18
  async def list():
16
19
  """List all ..."""
@@ -2,6 +2,6 @@
2
2
  PROJECT_NAME = "MyProject"
3
3
  DATABASE_URL = "sqlite://db.sqlite3"
4
4
  INSTALLED_APPS = [
5
- #'ohmyapi_auth',
5
+ #"ohmyapi_auth",
6
6
  ]
7
7
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ohmyapi
3
- Version: 0.1.24
3
+ Version: 0.1.25
4
4
  Summary: A Django-like but async web-framework based on FastAPI and TortoiseORM.
5
5
  License-Expression: MIT
6
6
  Keywords: fastapi,tortoise,orm,async,web-framework
@@ -62,7 +62,7 @@ It is ***blazingly fast***, extremely ***fun to use*** and comes with ***batteri
62
62
  **Creating a Project**
63
63
 
64
64
  ```
65
- pip install ohmyapi
65
+ pipx install ohmyapi
66
66
  ohmyapi startproject myproject
67
67
  cd myproject
68
68
  ```
@@ -159,24 +159,29 @@ from ohmyapi.db.exceptions import DoesNotExist
159
159
 
160
160
  from .models import Tournament
161
161
 
162
- # Expose your app's routes via `router = fastapi.APIRouter`.
163
- # Use prefixes wisely to avoid cross-app namespace-collisions.
162
+ # OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
163
+ # add their routes to the main project router.
164
+ #
165
+ # Note:
166
+ # Use prefixes wisely to avoid cross-app namespace-collisions!
164
167
  # Tags improve the UX of the OpenAPI docs at /docs.
165
- router = APIRouter(prefix="/tournament", tags=['Tournament'])
168
+ #
169
+ tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
166
170
 
167
- @router.get("/")
171
+
172
+ @tournament_router.get("/")
168
173
  async def list():
169
174
  queryset = Tournament.all()
170
175
  return await Tournament.Schema.model.from_queryset(queryset)
171
176
 
172
177
 
173
- @router.post("/", status_code=HTTPStatus.CREATED)
178
+ @tournament_router.post("/", status_code=HTTPStatus.CREATED)
174
179
  async def post(tournament: Tournament.Schema.readonly):
175
180
  queryset = Tournament.create(**payload.model_dump())
176
181
  return await Tournament.Schema.model.from_queryset(queryset)
177
182
 
178
183
 
179
- @router.get("/:id")
184
+ @tournament_router.get("/:id")
180
185
  async def get(id: str):
181
186
  try:
182
187
  queryset = Tournament.get(id=id)
@@ -184,6 +189,16 @@ async def get(id: str):
184
189
  except DoesNotExist:
185
190
  raise HTTPException(status_code=404, detail="not found")
186
191
 
192
+
193
+ @tournament_router.delete("/:id")
194
+ async def delete(id: str):
195
+ try:
196
+ tournament = await Tournament.get(id=id)
197
+ return await Tournament.Schema.model.from_queryset(tournament.delete())
198
+ except DoesNotExist:
199
+ raise HTTPException(status_code=404, detail="not found")
200
+
201
+
187
202
  ...
188
203
  ```
189
204
 
@@ -9,20 +9,20 @@ ohmyapi/builtin/demo/models.py,sha256=N3LnHLEa5wYBvaQBImCR4SdZvRYGuwM_iyLCeh9QY8
9
9
  ohmyapi/builtin/demo/routes.py,sha256=DQ-wO9O0lTJkYqAjVSp0jBs9pavs5vS9IlHXRePU-Ng,1806
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=i4dI7mC59rw0blMOeVGawUm8v5id3ZllLlP8RLo1GT0,9419
12
+ ohmyapi/core/runtime.py,sha256=i-yeFN_mwk2EIisKWM78yO09lPvApX9J_gr_OXmXlGc,9553
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=dFpmfrfN1pwOsD6MAa_MmI7aP4kKJ2ZiijobWHsfyDs,873
16
+ ohmyapi/core/templates/app/routes.py.j2,sha256=HQOf_9VqMgP3CCtf5IHNePubomiWKEf8D6qed33uLBI,948
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
- ohmyapi/core/templates/project/settings.py.j2,sha256=RBKGB8MZWPM3Bp0a57Y1YrSvSXxh502TUnJqbbu48Ig,138
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
23
  ohmyapi/db/model/model.py,sha256=WTf41ByCtfk9c_O6QCsO9KA0avHL3zGMZ6SEdw5GOuc,2420
24
24
  ohmyapi/router.py,sha256=6Exv6sVPVyiIYxxAQbxQhFRX74MKTUPWXIBwC7UZ-ww,82
25
- ohmyapi-0.1.24.dist-info/METADATA,sha256=YbyF-6_5QGYVomyCh_BJWzN8IKGqBBTQ6O342yjwY8E,9626
26
- ohmyapi-0.1.24.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
27
- ohmyapi-0.1.24.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
28
- ohmyapi-0.1.24.dist-info/RECORD,,
25
+ ohmyapi-0.1.25.dist-info/METADATA,sha256=diqmmkix3alQdWz3CHtZBvOZeFMPJHGJsx6-UTRSN1U,10040
26
+ ohmyapi-0.1.25.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
27
+ ohmyapi-0.1.25.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
28
+ ohmyapi-0.1.25.dist-info/RECORD,,