maleo-foundation 0.2.12__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.
@@ -10,8 +10,7 @@ class BaseClientParametersTransfers:
10
10
  BaseParameterSchemas.SortColumns,
11
11
  BaseGeneralSchemas.Search,
12
12
  BaseGeneralSchemas.Statuses,
13
- BaseParameterSchemas.DateFilters,
14
- BaseGeneralSchemas.Ids,
13
+ BaseParameterSchemas.DateFilters
15
14
  ):
16
15
  pass
17
16
 
@@ -51,15 +50,16 @@ class BaseClientParametersTransfers:
51
50
  self.filters = filter
52
51
 
53
52
  return self
54
-
55
- def to_query_params(self) -> dict[str, Any]:
56
- params = {
53
+
54
+ @property
55
+ def query_params(self) -> dict[str, Any]:
56
+ raw_params = {
57
+ "filters": self.filters,
58
+ "statuses": self.statuses,
57
59
  "search": self.search,
58
60
  "sorts": self.sorts,
59
- "filters": self.filters,
60
61
  }
61
- if hasattr(self, "statuses") and self.statuses is not None:
62
- params["statuses"] = self.statuses
62
+ params = {k: v for k, v in raw_params.items() if v not in (None, [], "")}
63
63
  return params
64
64
 
65
65
  class GetPaginatedMultiple(
@@ -104,15 +104,16 @@ class BaseClientParametersTransfers:
104
104
  self.filters = filter
105
105
 
106
106
  return self
107
-
108
- def to_query_params(self) -> dict[str, Any]:
109
- params = {
110
- "page": self.page,
111
- "limit": self.limit,
107
+
108
+ @property
109
+ def query_params(self) -> dict[str, Any]:
110
+ raw_params = {
111
+ "filters": self.filters,
112
+ "statuses": self.statuses,
112
113
  "search": self.search,
113
114
  "sorts": self.sorts,
114
- "filters": self.filters,
115
+ "page": self.page,
116
+ "limit": self.limit
115
117
  }
116
- if hasattr(self, "statuses") and self.statuses is not None:
117
- params["statuses"] = self.statuses
118
+ params = {k: v for k, v in raw_params.items() if v not in (None, [], "")}
118
119
  return params
@@ -1,19 +1,17 @@
1
1
  from __future__ import annotations
2
2
  from datetime import datetime
3
- from pydantic import BaseModel, Field, model_validator
4
- from typing import Optional, Self
3
+ from pydantic import model_validator
4
+ from typing import Self
5
5
  from maleo_foundation.enums import BaseEnums
6
6
  from maleo_foundation.models.schemas.general import BaseGeneralSchemas
7
7
  from maleo_foundation.models.schemas.parameter import BaseParameterSchemas
8
- from maleo_foundation.types import BaseTypes
9
8
 
10
9
  class BaseServiceParametersTransfers:
11
10
  class GetUnpaginatedMultipleQuery(
12
11
  BaseParameterSchemas.Sorts,
13
12
  BaseGeneralSchemas.Search,
14
13
  BaseGeneralSchemas.Statuses,
15
- BaseParameterSchemas.Filters,
16
- BaseGeneralSchemas.Ids
14
+ BaseParameterSchemas.Filters
17
15
  ): pass
18
16
 
19
17
  class GetUnpaginatedMultiple(
@@ -131,30 +129,4 @@ class BaseServiceParametersTransfers:
131
129
 
132
130
  #* Update date_filters
133
131
  self.date_filters = date_filters
134
- return self
135
-
136
- class UniqueFieldCheck(BaseModel):
137
- operation:BaseEnums.OperationType = Field(..., description="Operation to be conducted")
138
- field:BaseEnums.IdentifierTypes = Field(..., description="Field to be checked")
139
- new_value:BaseTypes.OptionalAny = Field(..., description="New field's value")
140
- old_value:BaseTypes.OptionalAny = Field(None, description="Old field's value")
141
- nullable:bool = Field(False, description="Whether to allow null field's value")
142
- suggestion:BaseTypes.OptionalString = Field(None, description="Suggestion on discrepancy")
143
-
144
- UniqueFieldChecks = list[UniqueFieldCheck]
145
-
146
- status_update_criterias:dict[
147
- BaseEnums.StatusUpdateAction,
148
- Optional[list[BaseEnums.StatusType]]
149
- ] = {
150
- BaseEnums.StatusUpdateAction.DELETE: None,
151
- BaseEnums.StatusUpdateAction.RESTORE: None,
152
- BaseEnums.StatusUpdateAction.DEACTIVATE: [
153
- BaseEnums.StatusType.INACTIVE,
154
- BaseEnums.StatusType.ACTIVE,
155
- ],
156
- BaseEnums.StatusUpdateAction.ACTIVATE: [
157
- BaseEnums.StatusType.INACTIVE,
158
- BaseEnums.StatusType.ACTIVE,
159
- ]
160
- }
132
+ return self
@@ -1,58 +1,13 @@
1
1
  from fastapi import status
2
2
  from functools import wraps
3
- from typing import Awaitable, Callable, Dict, List, Type, Any
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.12
3
+ Version: 0.2.14
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -62,10 +62,10 @@ maleo_foundation/models/transfers/general/key.py,sha256=tLKkXbwNu7Oc1MdKa8-Y7TlB
62
62
  maleo_foundation/models/transfers/general/signature.py,sha256=J9xQy2HjpCQOnES7RJqsUnDgjFPuakQ1mxyfdTdstSE,297
63
63
  maleo_foundation/models/transfers/general/token.py,sha256=QckgF39hRAFU9GNXZsQ20kfaGom5Ppw5ShYaqDbeje8,2698
64
64
  maleo_foundation/models/transfers/parameters/__init__.py,sha256=oKW4RPIEISISRjsJzD8lsCGY1HhZRTzshPpWHcJu86k,353
65
- maleo_foundation/models/transfers/parameters/client.py,sha256=tn_Hwa-k-Utp5rODe7GylqZB8djIKKupgkUFscYCyLc,4059
65
+ maleo_foundation/models/transfers/parameters/client.py,sha256=3X1iCThKr72_vds4gdldB0YxTlXoLTF1rGbsXyjyBpg,4051
66
66
  maleo_foundation/models/transfers/parameters/general.py,sha256=WoekZJCIoAllhXdRIJkNRdNq0QEIn0bteiHJLtzkCxU,579
67
67
  maleo_foundation/models/transfers/parameters/key.py,sha256=ZhWcbPJZvl8AF_qlecG-4-9_Ym6EbU7nngRo3AtbScY,432
68
- maleo_foundation/models/transfers/parameters/service.py,sha256=d7Xy_R-DtLBRozyD6r8YnTiuKlE3sb9HMDCCq9WmUbY,6757
68
+ maleo_foundation/models/transfers/parameters/service.py,sha256=kG9C0it_pvX0kg2tYQeKl645IrosBkxSjr5vpQbIkx4,5494
69
69
  maleo_foundation/models/transfers/parameters/signature.py,sha256=ysYkALwqNXn13HP8xUOnPlboL9pgFLmQ9f7OpZe9dDw,483
70
70
  maleo_foundation/models/transfers/parameters/token.py,sha256=kIUhz86-9qEiWxZXIva33-iIdHDS9ca-_7SDvgOxitw,623
71
71
  maleo_foundation/models/transfers/parameters/encryption/__init__.py,sha256=w1-J_cVp8vPUVaAkTEpTTZ5S6R2wKxpqKj1Eu2cj-w0,322
@@ -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=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUUX6ipXBg,6396
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.12.dist-info/METADATA,sha256=R6VQSWtH1CEeeIq8ViRo1DqW6Qpc2PNtOcwFo6b1728,3419
114
- maleo_foundation-0.2.12.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
115
- maleo_foundation-0.2.12.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
116
- maleo_foundation-0.2.12.dist-info/RECORD,,
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,,