maleo-foundation 0.0.74__tar.gz → 0.0.75__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.
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/PKG-INFO +1 -1
- maleo_foundation-0.0.75/maleo_foundation/utils/controller.py +109 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/PKG-INFO +1 -1
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/pyproject.toml +1 -1
- maleo_foundation-0.0.74/maleo_foundation/utils/controller.py +0 -50
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/README.md +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/general/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/general/http.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/logging.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/secret.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/storage.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/utils/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/utils/logger.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/constants.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/db/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/db/engine.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/db/manager.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/db/session.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/db/table.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/enums.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/client.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/general.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/query.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/service.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/extended_types.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/middlewares/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/middlewares/base.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/middlewares/cors.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/responses.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/general.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/parameter.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/result.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/parameters/client.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/parameters/general.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/parameters/service.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/client/service.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/service/general.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/results/service/query.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/types.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/exceptions.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/formatter/__init__.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/formatter/case.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/logger.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/query.py +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/SOURCES.txt +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/dependency_links.txt +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/requires.txt +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/top_level.txt +0 -0
- {maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/setup.cfg +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from fastapi import status
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from typing import Awaitable, Callable, Dict, List, Type, Any
|
|
4
|
+
from maleo_foundation.types import BaseTypes
|
|
5
|
+
from maleo_foundation.enums import BaseEnums
|
|
6
|
+
from maleo_foundation.models.responses import BaseResponses
|
|
7
|
+
from maleo_foundation.models.transfers.parameters.general import BaseGeneralParametersTransfers
|
|
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
|
|
11
|
+
from maleo_foundation.expanded_types.service import ExpandedServiceTypes
|
|
12
|
+
|
|
13
|
+
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
|
+
@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 not 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
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from fastapi import status
|
|
2
|
-
from typing import Type, Any
|
|
3
|
-
from maleo_foundation.enums import BaseEnums
|
|
4
|
-
from maleo_foundation.models.responses import BaseResponses
|
|
5
|
-
from maleo_foundation.models.transfers.results.service.controllers.rest import BaseServiceRESTControllerResults
|
|
6
|
-
from maleo_foundation.models.transfers.parameters.service import BaseServiceParametersTransfers
|
|
7
|
-
from maleo_foundation.expanded_types.service import ExpandedServiceTypes
|
|
8
|
-
|
|
9
|
-
class BaseControllerUtils:
|
|
10
|
-
@staticmethod
|
|
11
|
-
def check_unique_existence(
|
|
12
|
-
check:BaseServiceParametersTransfers.UniqueFieldCheck,
|
|
13
|
-
get_single_parameters_class:Type[ExpandedServiceTypes.GetSingleParameter],
|
|
14
|
-
get_single_service_function:ExpandedServiceTypes.SyncGetSingleFunction,
|
|
15
|
-
create_failed_response_class:Type[BaseResponses.Fail],
|
|
16
|
-
update_failed_response_class:Type[BaseResponses.Fail],
|
|
17
|
-
**additional_get_parameters:Any
|
|
18
|
-
) -> BaseServiceRESTControllerResults:
|
|
19
|
-
"""Generic helper function to check if a unique value exists in the database."""
|
|
20
|
-
|
|
21
|
-
#* Return early if nullable and no new value
|
|
22
|
-
if check.nullable and check.new_value is None:
|
|
23
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
|
24
|
-
|
|
25
|
-
#* Return early if values are unchanged on update
|
|
26
|
-
if check.operation == BaseEnums.OperationType.UPDATE and check.old_value == check.new_value:
|
|
27
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
|
28
|
-
|
|
29
|
-
#* Prepare parameters to query for existing data
|
|
30
|
-
get_single_parameters = get_single_parameters_class(identifier=check.field, value=check.new_value)
|
|
31
|
-
|
|
32
|
-
#* Query the existing data using provided function
|
|
33
|
-
service_result:ExpandedServiceTypes.GetSingleResult = get_single_service_function(parameters=get_single_parameters, **additional_get_parameters)
|
|
34
|
-
if not service_result.success:
|
|
35
|
-
content = BaseResponses.ServerError.model_validate(service_result.model_dump(exclude_unset=True)).model_dump()
|
|
36
|
-
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
|
37
|
-
|
|
38
|
-
#* Handle case if duplicate is found
|
|
39
|
-
if service_result.data:
|
|
40
|
-
description = f"External error: {check.field} of '{check.new_value}' already exists in the database"
|
|
41
|
-
other = check.suggestion or f"Select another {check.field} value"
|
|
42
|
-
if check.operation == BaseEnums.OperationType.CREATE:
|
|
43
|
-
content = create_failed_response_class(description=description, other=other).model_dump()
|
|
44
|
-
elif check.operation == BaseEnums.OperationType.UPDATE:
|
|
45
|
-
content = update_failed_response_class(description=description, other=other).model_dump()
|
|
46
|
-
|
|
47
|
-
return BaseServiceRESTControllerResults(success=False, content=content, status_code=status.HTTP_400_BAD_REQUEST)
|
|
48
|
-
|
|
49
|
-
#* No duplicates found
|
|
50
|
-
return BaseServiceRESTControllerResults(success=True, content=None)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/general/__init__.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/general/http.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/logging.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/secret.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/google/cloud/storage.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/utils/__init__.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/clients/utils/logger.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/__init__.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/client.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/general.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/query.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/expanded_types/service.py
RENAMED
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/middlewares/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/__init__.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/general.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/parameter.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/schemas/result.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/models/transfers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/formatter/__init__.py
RENAMED
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation/utils/formatter/case.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maleo_foundation-0.0.74 → maleo_foundation-0.0.75}/maleo_foundation.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|