maleo-foundation 0.0.74__py3-none-any.whl → 0.0.76__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.
- maleo_foundation/utils/controller.py +62 -3
- {maleo_foundation-0.0.74.dist-info → maleo_foundation-0.0.76.dist-info}/METADATA +1 -1
- {maleo_foundation-0.0.74.dist-info → maleo_foundation-0.0.76.dist-info}/RECORD +5 -5
- {maleo_foundation-0.0.74.dist-info → maleo_foundation-0.0.76.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.0.74.dist-info → maleo_foundation-0.0.76.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
from fastapi import status
|
|
2
|
-
from
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from typing import Awaitable, Callable, Dict, List, Type, Any
|
|
4
|
+
from maleo_foundation.types import BaseTypes
|
|
3
5
|
from maleo_foundation.enums import BaseEnums
|
|
4
6
|
from maleo_foundation.models.responses import BaseResponses
|
|
5
|
-
from maleo_foundation.models.transfers.
|
|
7
|
+
from maleo_foundation.models.transfers.parameters.general import BaseGeneralParametersTransfers
|
|
6
8
|
from maleo_foundation.models.transfers.parameters.service import BaseServiceParametersTransfers
|
|
9
|
+
from maleo_foundation.models.transfers.results.service.controllers.rest import BaseServiceRESTControllerResults
|
|
10
|
+
from maleo_foundation.expanded_types.general import BaseGeneralExpandedTypes
|
|
7
11
|
from maleo_foundation.expanded_types.service import ExpandedServiceTypes
|
|
8
12
|
|
|
9
13
|
class BaseControllerUtils:
|
|
@@ -47,4 +51,59 @@ class BaseControllerUtils:
|
|
|
47
51
|
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_400_BAD_REQUEST)
|
|
48
52
|
|
|
49
53
|
#* No duplicates found
|
|
50
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
|
54
|
+
return BaseServiceRESTControllerResults(success=True, content=None)
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def field_expansion_handler(
|
|
58
|
+
expandable_fields_dependencies_map:BaseTypes.OptionalStringToListOfStringDict = None,
|
|
59
|
+
field_expansion_processors:BaseGeneralExpandedTypes.OptionalListOfFieldExpansionProcessor = None
|
|
60
|
+
):
|
|
61
|
+
"""
|
|
62
|
+
Decorator to handle expandable fields validation and processing.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
validation_rules: Dictionary where keys are required fields and values are lists of dependent fields
|
|
66
|
+
field_expansion_processors: Dictionary of field names to processor functions that handle that field's data
|
|
67
|
+
"""
|
|
68
|
+
def decorator(func:Callable[..., Awaitable[BaseServiceRESTControllerResults]]):
|
|
69
|
+
@wraps(func)
|
|
70
|
+
async def wrapper(parameters, *args, **kwargs):
|
|
71
|
+
expand:BaseTypes.OptionalListOfStrings = getattr(parameters, 'expand', None)
|
|
72
|
+
|
|
73
|
+
#* Validate expandable fields dependencies
|
|
74
|
+
if expand is not None and expandable_fields_dependencies_map is not None:
|
|
75
|
+
for dependency, dependents in expandable_fields_dependencies_map.items():
|
|
76
|
+
if dependency not in expand:
|
|
77
|
+
for dependent in dependents:
|
|
78
|
+
if dependent in expand:
|
|
79
|
+
other = f"'{dependency}' must also be expanded if '{dependent}' is expanded"
|
|
80
|
+
content = BaseResponses.InvalidExpand(other=other).model_dump()
|
|
81
|
+
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_400_BAD_REQUEST)
|
|
82
|
+
|
|
83
|
+
#* Call the original function
|
|
84
|
+
result = await func(parameters, *args, **kwargs)
|
|
85
|
+
|
|
86
|
+
if not isinstance(result.content, Dict):
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
#* Process the fields if needed
|
|
90
|
+
if result.success and result.content.get("data", None) is not None and field_expansion_processors is not None:
|
|
91
|
+
data = result.content["data"]
|
|
92
|
+
if isinstance(data, List):
|
|
93
|
+
for idx, dt in enumerate(data):
|
|
94
|
+
for processor in field_expansion_processors:
|
|
95
|
+
raw_parameters = {"data": dt, "expand": expand}
|
|
96
|
+
parameters = BaseGeneralParametersTransfers.FieldExpansionProcessor.model_validate(raw_parameters)
|
|
97
|
+
dt = processor(parameters)
|
|
98
|
+
data[idx] = dt
|
|
99
|
+
elif isinstance(data, Dict):
|
|
100
|
+
raw_parameters = {"data": data, "expand": expand}
|
|
101
|
+
parameters = BaseGeneralParametersTransfers.FieldExpansionProcessor.model_validate(raw_parameters)
|
|
102
|
+
for processor in field_expansion_processors:
|
|
103
|
+
data = processor(parameters)
|
|
104
|
+
result.content["data"] = data
|
|
105
|
+
result.process_response()
|
|
106
|
+
|
|
107
|
+
return result
|
|
108
|
+
return wrapper
|
|
109
|
+
return decorator
|
|
@@ -48,13 +48,13 @@ maleo_foundation/models/transfers/results/service/query.py,sha256=G5A4FRkHyRRlpu
|
|
|
48
48
|
maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256=HZJWMy2dskzOCzLmp_UaL9rjbQ-sDMI7sd2bXb-4QOU,175
|
|
49
49
|
maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
|
|
50
50
|
maleo_foundation/utils/__init__.py,sha256=FavmL5XYGCm955EAKiWWcXYeU15p5rSzfcglpV2yI6c,387
|
|
51
|
-
maleo_foundation/utils/controller.py,sha256=
|
|
51
|
+
maleo_foundation/utils/controller.py,sha256=vC2B2IfuwM4CqsFgpmawT1uniAJ_S9-rP7vXXAMlmrY,6397
|
|
52
52
|
maleo_foundation/utils/exceptions.py,sha256=nk3rD57fDR-D7BQkU1JEKV-Mu7FGMpLSEsqxdDZdKjU,4532
|
|
53
53
|
maleo_foundation/utils/logger.py,sha256=978P57JOhGR-WIu7xdPXBIwd3JrfLLA8WerVzxhE_Fs,3408
|
|
54
54
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
|
55
55
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
|
56
56
|
maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
|
|
57
|
-
maleo_foundation-0.0.
|
|
58
|
-
maleo_foundation-0.0.
|
|
59
|
-
maleo_foundation-0.0.
|
|
60
|
-
maleo_foundation-0.0.
|
|
57
|
+
maleo_foundation-0.0.76.dist-info/METADATA,sha256=R2JVBCmmGvCNmNzP9of4uM3tbCo4eCaN7slXucM1FMk,3160
|
|
58
|
+
maleo_foundation-0.0.76.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
59
|
+
maleo_foundation-0.0.76.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
|
60
|
+
maleo_foundation-0.0.76.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|