maleo-foundation 0.2.13__py3-none-any.whl → 0.2.14__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 +1 -46
- {maleo_foundation-0.2.13.dist-info → maleo_foundation-0.2.14.dist-info}/METADATA +1 -1
- {maleo_foundation-0.2.13.dist-info → maleo_foundation-0.2.14.dist-info}/RECORD +5 -5
- {maleo_foundation-0.2.13.dist-info → maleo_foundation-0.2.14.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.2.13.dist-info → maleo_foundation-0.2.14.dist-info}/top_level.txt +0 -0
@@ -1,58 +1,13 @@
|
|
1
1
|
from fastapi import status
|
2
2
|
from functools import wraps
|
3
|
-
from typing import Awaitable, Callable, Dict, List
|
3
|
+
from typing import Awaitable, Callable, Dict, List
|
4
4
|
from maleo_foundation.types import BaseTypes
|
5
|
-
from maleo_foundation.enums import BaseEnums
|
6
5
|
from maleo_foundation.models.responses import BaseResponses
|
7
6
|
from maleo_foundation.models.transfers.parameters.general import BaseGeneralParametersTransfers
|
8
|
-
from maleo_foundation.models.transfers.parameters.service import BaseServiceParametersTransfers
|
9
7
|
from maleo_foundation.models.transfers.results.service.controllers.rest import BaseServiceRESTControllerResults
|
10
8
|
from maleo_foundation.expanded_types.general import BaseGeneralExpandedTypes
|
11
|
-
from maleo_foundation.expanded_types.service import ExpandedServiceTypes
|
12
9
|
|
13
10
|
class BaseControllerUtils:
|
14
|
-
@staticmethod
|
15
|
-
def check_unique_existence(
|
16
|
-
check:BaseServiceParametersTransfers.UniqueFieldCheck,
|
17
|
-
get_single_parameters_class:Type[ExpandedServiceTypes.GetSingleParameter],
|
18
|
-
get_single_service_function:ExpandedServiceTypes.SyncGetSingleFunction,
|
19
|
-
create_failed_response_class:Type[BaseResponses.Fail],
|
20
|
-
update_failed_response_class:Type[BaseResponses.Fail],
|
21
|
-
**additional_get_parameters:Any
|
22
|
-
) -> BaseServiceRESTControllerResults:
|
23
|
-
"""Generic helper function to check if a unique value exists in the database."""
|
24
|
-
|
25
|
-
#* Return early if nullable and no new value
|
26
|
-
if check.nullable and check.new_value is None:
|
27
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
28
|
-
|
29
|
-
#* Return early if values are unchanged on update
|
30
|
-
if check.operation == BaseEnums.OperationType.UPDATE and check.old_value == check.new_value:
|
31
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
32
|
-
|
33
|
-
#* Prepare parameters to query for existing data
|
34
|
-
get_single_parameters = get_single_parameters_class(identifier=check.field, value=check.new_value)
|
35
|
-
|
36
|
-
#* Query the existing data using provided function
|
37
|
-
service_result:ExpandedServiceTypes.GetSingleResult = get_single_service_function(parameters=get_single_parameters, **additional_get_parameters)
|
38
|
-
if not service_result.success:
|
39
|
-
content = BaseResponses.ServerError.model_validate(service_result.model_dump(exclude_unset=True)).model_dump()
|
40
|
-
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
41
|
-
|
42
|
-
#* Handle case if duplicate is found
|
43
|
-
if service_result.data:
|
44
|
-
description = f"External error: {check.field} of '{check.new_value}' already exists in the database"
|
45
|
-
other = check.suggestion or f"Select another {check.field} value"
|
46
|
-
if check.operation == BaseEnums.OperationType.CREATE:
|
47
|
-
content = create_failed_response_class(description=description, other=other).model_dump()
|
48
|
-
elif check.operation == BaseEnums.OperationType.UPDATE:
|
49
|
-
content = update_failed_response_class(description=description, other=other).model_dump()
|
50
|
-
|
51
|
-
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_400_BAD_REQUEST)
|
52
|
-
|
53
|
-
#* No duplicates found
|
54
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
55
|
-
|
56
11
|
@staticmethod
|
57
12
|
def field_expansion_handler(
|
58
13
|
expandable_fields_dependencies_map:BaseTypes.OptionalStringToListOfStringDict = None,
|
@@ -93,7 +93,7 @@ maleo_foundation/models/transfers/results/service/query.py,sha256=xHHPWCYx6NrKK9
|
|
93
93
|
maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256=HZJWMy2dskzOCzLmp_UaL9rjbQ-sDMI7sd2bXb-4QOU,175
|
94
94
|
maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
|
95
95
|
maleo_foundation/utils/__init__.py,sha256=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZMdOthY,520
|
96
|
-
maleo_foundation/utils/controller.py,sha256=
|
96
|
+
maleo_foundation/utils/controller.py,sha256=rzuWJVbR0eNxKpzrIGbglFAUjqBHrQ8eNCqGq-oLXr0,3643
|
97
97
|
maleo_foundation/utils/exceptions.py,sha256=YKQ2hwVHUFlLAeup9FmCGptGIgdAuxTmTrD8A3gqURA,4078
|
98
98
|
maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
|
99
99
|
maleo_foundation/utils/logging.py,sha256=W5Fhk_xAXVqSujaY8mv3hRH4wlQSpUn4ReuMoiKcQa4,7759
|
@@ -110,7 +110,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
|
|
110
110
|
maleo_foundation/utils/loaders/credential/google.py,sha256=deksZXT5wPhEsSMHbZ3x05WHXxCjLDt76Ns-1Tmhp7g,948
|
111
111
|
maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
|
112
112
|
maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
|
113
|
-
maleo_foundation-0.2.
|
114
|
-
maleo_foundation-0.2.
|
115
|
-
maleo_foundation-0.2.
|
116
|
-
maleo_foundation-0.2.
|
113
|
+
maleo_foundation-0.2.14.dist-info/METADATA,sha256=aN9I-T0Pwf5zqS7iIZrH55r8bJYM4BB4aFDvLU7SbjQ,3419
|
114
|
+
maleo_foundation-0.2.14.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
115
|
+
maleo_foundation-0.2.14.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
116
|
+
maleo_foundation-0.2.14.dist-info/RECORD,,
|
File without changes
|
File without changes
|