apexdevkit 1.4.1__tar.gz → 1.4.3__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.
Files changed (32) hide show
  1. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/PKG-INFO +1 -1
  2. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/router.py +103 -22
  3. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/pyproject.toml +1 -1
  4. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/LICENSE +0 -0
  5. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/README.md +0 -0
  6. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/__init__.py +0 -0
  7. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/annotation/__init__.py +0 -0
  8. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/annotation/deprecate.py +0 -0
  9. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/error.py +0 -0
  10. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/__init__.py +0 -0
  11. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/builder.py +0 -0
  12. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/dependable.py +0 -0
  13. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/docs.py +0 -0
  14. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/response.py +0 -0
  15. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/schema.py +0 -0
  16. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/fastapi/service.py +0 -0
  17. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/__init__.py +0 -0
  18. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/fake.py +0 -0
  19. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/fluent.py +0 -0
  20. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/httpx.py +0 -0
  21. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/json.py +0 -0
  22. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/http/url.py +0 -0
  23. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/py.typed +0 -0
  24. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/repository/__init__.py +0 -0
  25. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/repository/connector.py +0 -0
  26. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/repository/database.py +0 -0
  27. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/repository/in_memory.py +0 -0
  28. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/repository/interface.py +0 -0
  29. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/testing/__init__.py +0 -0
  30. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/testing/database.py +0 -0
  31. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/testing/fake.py +0 -0
  32. {apexdevkit-1.4.1 → apexdevkit-1.4.3}/apexdevkit/testing/rest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.4.1
3
+ Version: 1.4.3
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -1,9 +1,10 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from dataclasses import dataclass, field
3
3
  from functools import cached_property
4
- from typing import Annotated, Any, Iterable, Self, TypeVar
4
+ from typing import Annotated, Any, Callable, Iterable, Self, TypeVar
5
5
 
6
6
  from fastapi import APIRouter, Depends, Path
7
+ from fastapi.requests import Request
7
8
  from fastapi.responses import JSONResponse
8
9
 
9
10
  from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
@@ -107,6 +108,10 @@ class PreBuiltRestfulService(RestfulServiceBuilder):
107
108
  return self.service
108
109
 
109
110
 
111
+ def no_user(request: Request) -> None:
112
+ pass
113
+
114
+
110
115
  @dataclass
111
116
  class RestfulRouter:
112
117
  service: RestfulService | None = None
@@ -173,7 +178,11 @@ class RestfulRouter:
173
178
 
174
179
  return self
175
180
 
176
- def with_create_one_endpoint(self, is_documented: bool = True) -> Self:
181
+ def with_create_one_endpoint(
182
+ self,
183
+ is_documented: bool = True,
184
+ extract_user: Callable[[Request], Any] = no_user,
185
+ ) -> Self:
177
186
  parent_id_type = Annotated[
178
187
  str,
179
188
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -191,9 +200,13 @@ class RestfulRouter:
191
200
  response_model=self.schema.for_item(),
192
201
  include_in_schema=is_documented,
193
202
  )
194
- def create_one(parent_id: parent_id_type, item: item_type) -> _Response:
203
+ def create_one(
204
+ user: Annotated[Any, Depends(extract_user)],
205
+ parent_id: parent_id_type,
206
+ item: item_type,
207
+ ) -> _Response:
195
208
  try:
196
- service = self.infra.with_parent(parent_id).build()
209
+ service = self.infra.with_user(user).with_parent(parent_id).build()
197
210
  except DoesNotExistError as e:
198
211
  return JSONResponse(
199
212
  RestfulResponse(RestfulName(self.parent)).not_found(e), 404
@@ -208,7 +221,11 @@ class RestfulRouter:
208
221
 
209
222
  return self
210
223
 
211
- def with_create_many_endpoint(self, is_documented: bool = True) -> Self:
224
+ def with_create_many_endpoint(
225
+ self,
226
+ is_documented: bool = True,
227
+ extract_user: Callable[[Request], Any] = no_user,
228
+ ) -> Self:
212
229
  parent_id_type = Annotated[
213
230
  str,
214
231
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -226,9 +243,13 @@ class RestfulRouter:
226
243
  response_model=self.schema.for_collection(),
227
244
  include_in_schema=is_documented,
228
245
  )
229
- def create_many(parent_id: parent_id_type, items: collection_type) -> _Response:
246
+ def create_many(
247
+ user: Annotated[Any, Depends(extract_user)],
248
+ parent_id: parent_id_type,
249
+ items: collection_type,
250
+ ) -> _Response:
230
251
  try:
231
- service = self.infra.with_parent(parent_id).build()
252
+ service = self.infra.with_user(user).with_parent(parent_id).build()
232
253
  except DoesNotExistError as e:
233
254
  return JSONResponse(
234
255
  RestfulResponse(RestfulName(self.parent)).not_found(e), 404
@@ -241,7 +262,11 @@ class RestfulRouter:
241
262
 
242
263
  return self
243
264
 
244
- def with_read_one_endpoint(self, is_documented: bool = True) -> Self:
265
+ def with_read_one_endpoint(
266
+ self,
267
+ is_documented: bool = True,
268
+ extract_user: Callable[[Request], Any] = no_user,
269
+ ) -> Self:
245
270
  id_type = Annotated[str, Path(alias=self.id_alias)]
246
271
  parent_id_type = Annotated[
247
272
  str,
@@ -255,8 +280,17 @@ class RestfulRouter:
255
280
  response_model=self.schema.for_item(),
256
281
  include_in_schema=is_documented,
257
282
  )
258
- def read_one(parent_id: parent_id_type, item_id: id_type) -> _Response:
259
- service = self.infra.with_parent(parent_id).build()
283
+ def read_one(
284
+ user: Annotated[Any, Depends(extract_user)],
285
+ parent_id: parent_id_type,
286
+ item_id: id_type,
287
+ ) -> _Response:
288
+ try:
289
+ service = self.infra.with_user(user).with_parent(parent_id).build()
290
+ except DoesNotExistError as e:
291
+ return JSONResponse(
292
+ RestfulResponse(RestfulName(self.parent)).not_found(e), 404
293
+ )
260
294
 
261
295
  try:
262
296
  return self.response.found_one(service.read_one(item_id))
@@ -265,7 +299,11 @@ class RestfulRouter:
265
299
 
266
300
  return self
267
301
 
268
- def with_read_all_endpoint(self, is_documented: bool = True) -> Self:
302
+ def with_read_all_endpoint(
303
+ self,
304
+ is_documented: bool = True,
305
+ extract_user: Callable[[Request], Any] = no_user,
306
+ ) -> Self:
269
307
  parent_id_type = Annotated[
270
308
  str,
271
309
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -278,14 +316,26 @@ class RestfulRouter:
278
316
  response_model=self.schema.for_collection(),
279
317
  include_in_schema=is_documented,
280
318
  )
281
- def read_all(parent_id: parent_id_type) -> _Response:
282
- service = self.infra.with_parent(parent_id).build()
319
+ def read_all(
320
+ user: Annotated[Any, Depends(extract_user)],
321
+ parent_id: parent_id_type,
322
+ ) -> _Response:
323
+ try:
324
+ service = self.infra.with_user(user).with_parent(parent_id).build()
325
+ except DoesNotExistError as e:
326
+ return JSONResponse(
327
+ RestfulResponse(RestfulName(self.parent)).not_found(e), 404
328
+ )
283
329
 
284
330
  return self.response.found_many(list(service.read_all()))
285
331
 
286
332
  return self
287
333
 
288
- def with_update_one_endpoint(self, is_documented: bool = True) -> Self:
334
+ def with_update_one_endpoint(
335
+ self,
336
+ is_documented: bool = True,
337
+ extract_user: Callable[[Request], Any] = no_user,
338
+ ) -> Self:
289
339
  parent_id_type = Annotated[
290
340
  str,
291
341
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -304,12 +354,17 @@ class RestfulRouter:
304
354
  include_in_schema=is_documented,
305
355
  )
306
356
  def update_one(
357
+ user: Annotated[Any, Depends(extract_user)],
307
358
  parent_id: parent_id_type,
308
359
  item_id: id_type,
309
360
  updates: update_type,
310
361
  ) -> _Response:
311
- service = self.infra.with_parent(parent_id).build()
312
-
362
+ try:
363
+ service = self.infra.with_user(user).with_parent(parent_id).build()
364
+ except DoesNotExistError as e:
365
+ return JSONResponse(
366
+ RestfulResponse(RestfulName(self.parent)).not_found(e), 404
367
+ )
313
368
  try:
314
369
  service.update_one(item_id, **updates)
315
370
  except DoesNotExistError as e:
@@ -321,7 +376,11 @@ class RestfulRouter:
321
376
 
322
377
  return self
323
378
 
324
- def with_update_many_endpoint(self, is_documented: bool = True) -> Self:
379
+ def with_update_many_endpoint(
380
+ self,
381
+ is_documented: bool = True,
382
+ extract_user: Callable[[Request], Any] = no_user,
383
+ ) -> Self:
325
384
  parent_id_type = Annotated[
326
385
  str,
327
386
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -338,8 +397,17 @@ class RestfulRouter:
338
397
  response_model=self.schema.for_no_data(),
339
398
  include_in_schema=is_documented,
340
399
  )
341
- def update_many(parent_id: parent_id_type, items: collection_type) -> _Response:
342
- service = self.infra.with_parent(parent_id).build()
400
+ def update_many(
401
+ user: Annotated[Any, Depends(extract_user)],
402
+ parent_id: parent_id_type,
403
+ items: collection_type,
404
+ ) -> _Response:
405
+ try:
406
+ service = self.infra.with_user(user).with_parent(parent_id).build()
407
+ except DoesNotExistError as e:
408
+ return JSONResponse(
409
+ RestfulResponse(RestfulName(self.parent)).not_found(e), 404
410
+ )
343
411
 
344
412
  service.update_many(items)
345
413
 
@@ -347,7 +415,11 @@ class RestfulRouter:
347
415
 
348
416
  return self
349
417
 
350
- def with_delete_one_endpoint(self, is_documented: bool = True) -> Self:
418
+ def with_delete_one_endpoint(
419
+ self,
420
+ is_documented: bool = True,
421
+ extract_user: Callable[[Request], Any] = no_user,
422
+ ) -> Self:
351
423
  parent_id_type = Annotated[
352
424
  str,
353
425
  Path(alias=self.parent_id_alias, default_factory=str),
@@ -361,8 +433,17 @@ class RestfulRouter:
361
433
  response_model=self.schema.for_no_data(),
362
434
  include_in_schema=is_documented,
363
435
  )
364
- def delete_one(parent_id: parent_id_type, item_id: id_type) -> _Response:
365
- service = self.infra.with_parent(parent_id).build()
436
+ def delete_one(
437
+ user: Annotated[Any, Depends(extract_user)],
438
+ parent_id: parent_id_type,
439
+ item_id: id_type,
440
+ ) -> _Response:
441
+ try:
442
+ service = self.infra.with_user(user).with_parent(parent_id).build()
443
+ except DoesNotExistError as e:
444
+ return JSONResponse(
445
+ RestfulResponse(RestfulName(self.parent)).not_found(e), 404
446
+ )
366
447
 
367
448
  try:
368
449
  service.delete_one(item_id)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.4.1"
3
+ version = "1.4.3"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
File without changes
File without changes