architectonics 0.0.35__py3-none-any.whl → 0.0.37__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.
@@ -68,11 +68,11 @@ class BaseService:
68
68
  model_id: str,
69
69
  ) -> ServiceResult[BaseModel, BaseModelValidationErrors]:
70
70
 
71
- try:
72
- model = await self._repository.get_model_by_id(
73
- model_id=model_id,
74
- )
75
- except ObjectNotFoundException:
71
+ model = await self._repository.get_model_by_id(
72
+ model_id=model_id,
73
+ )
74
+
75
+ if model is None:
76
76
  return ServiceResult[BaseModel, BaseModelValidationErrors].failure(
77
77
  error_message="object_not_found",
78
78
  )
@@ -0,0 +1,52 @@
1
+ from uuid import UUID
2
+
3
+ from fastapi import Depends, Header, HTTPException
4
+ from starlette.status import HTTP_400_BAD_REQUEST
5
+
6
+
7
+ def get_user_id(
8
+ x_user_id: str = Header(
9
+ alias="X-User-Id",
10
+ description="Идентификатор пользователя",
11
+ ),
12
+ ) -> str:
13
+ if not x_user_id:
14
+ raise HTTPException(
15
+ status_code=HTTP_400_BAD_REQUEST,
16
+ detail="X-User-Id header is required",
17
+ )
18
+
19
+ try:
20
+ _ = UUID(x_user_id, version=4) # version=4 для проверки UUID v4
21
+ except ValueError:
22
+ raise HTTPException(
23
+ status_code=HTTP_400_BAD_REQUEST,
24
+ detail="not_valid_uuid",
25
+ )
26
+
27
+ return x_user_id
28
+
29
+
30
+ def get_user_roles(
31
+ x_user_roles: str = Header(
32
+ alias="X-User-Roles",
33
+ description="Роли пользователя",
34
+ ),
35
+ ) -> str:
36
+ if not x_user_roles:
37
+ raise HTTPException(
38
+ status_code=HTTP_400_BAD_REQUEST,
39
+ detail="X-User-Roles header is required",
40
+ )
41
+
42
+ return x_user_roles.split(",")
43
+
44
+
45
+ class UserAuthService:
46
+ def __init__(
47
+ self,
48
+ user_id: str = Depends(get_user_id),
49
+ user_roles: list[str] = Depends(get_user_roles),
50
+ ):
51
+ self.user_id = user_id
52
+ self.user_roles = user_roles
@@ -49,7 +49,7 @@ class BaseRepository(ABC):
49
49
  async def get_model_by_id(
50
50
  self,
51
51
  model_id: str,
52
- ) -> BaseModel:
52
+ ) -> BaseModel | None:
53
53
 
54
54
  statement = select(
55
55
  self._entity,
@@ -66,7 +66,7 @@ class BaseRepository(ABC):
66
66
  entity = result.scalars().first()
67
67
 
68
68
  if entity is None:
69
- raise ObjectNotFoundException()
69
+ return None
70
70
 
71
71
  return entity.to_model()
72
72
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: architectonics
3
- Version: 0.0.35
3
+ Version: 0.0.37
4
4
  Summary:
5
5
  Author: Your Name
6
6
  Author-email: you@example.com
@@ -13,7 +13,8 @@ architectonics/core/result/error_message.py,sha256=sMIMVt58wGo33E9lD4r6k9tRkgL2T
13
13
  architectonics/core/result/service_result.py,sha256=VwjegZKR38ocAEriY_0rnnPn69u09HDja4y3iKq0z9w,1879
14
14
  architectonics/core/schemas/base_schemas.py,sha256=4ghwg7h06uIoBRkXGtWDFQA7Yb6Hvo4AsIA80xmSlFk,415
15
15
  architectonics/core/services/base_schemas.py,sha256=9PpCcf5GaE68s2VDKiAWRNufhFL2iN5djOcMsir8HMk,295
16
- architectonics/core/services/base_service.py,sha256=hYYQ73icgMnwnDRjGd1rqYlE5qvsVvneKHosjEEHysU,4149
16
+ architectonics/core/services/base_service.py,sha256=dyu_G4JV9iL_teT10M9UhvGlN5D15165FABJRxcjWXU,4111
17
+ architectonics/core/services/user_auth_service.py,sha256=lQr_YdFkPP5p0WstUpsQ3htXyHeaaSlUjl_1XRJnFC0,1302
17
18
  architectonics/core/validation/base_model_validation_errors.py,sha256=Z3nGM3XaHbkW0z2qhVjwd8t0EbYULArIHARa0IYCNVg,306
18
19
  architectonics/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
20
  architectonics/infrastructure/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -22,7 +23,7 @@ architectonics/infrastructure/config/database_settings.py,sha256=d1HA8rQj3LMACEv
22
23
  architectonics/infrastructure/entities/base_entity.py,sha256=EqmmY2aVzqIdgJPsKBUBtesOfsmSSNrRuBGGQQ6bpJA,818
23
24
  architectonics/infrastructure/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
25
  architectonics/infrastructure/repositories/base_exceptions.py,sha256=kOeu3p90LHMxCcp2cCL_Anrsz4CTLtELWqma_RCQSqM,303
25
- architectonics/infrastructure/repositories/base_repository.py,sha256=y9Q2SPj1t55gRrUaNrSZ7SnuEGVYRAlwuU3fhNwtzt8,3585
26
- architectonics-0.0.35.dist-info/WHEEL,sha256=y3eDiaFVSNTPbgzfNn0nYn5tEn1cX6WrdetDlQM4xWw,83
27
- architectonics-0.0.35.dist-info/METADATA,sha256=xAEwbOoRpQui4bDEHoq492lae0wJ4ZrVXjEFseJtgpQ,469
28
- architectonics-0.0.35.dist-info/RECORD,,
26
+ architectonics/infrastructure/repositories/base_repository.py,sha256=RFERUHKTXCURSSME-GHkmBfbycSPTtiojYwBowjtNrw,3572
27
+ architectonics-0.0.37.dist-info/WHEEL,sha256=y3eDiaFVSNTPbgzfNn0nYn5tEn1cX6WrdetDlQM4xWw,83
28
+ architectonics-0.0.37.dist-info/METADATA,sha256=WYUiw3wsisUbwDzl2BlKGg6um97zA6qvNa465qkpY_E,469
29
+ architectonics-0.0.37.dist-info/RECORD,,