1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-10-07 15:33:51 +03:00

Refactor REST methods to use GetItemsResult type and improve type safety

- Updated return types of get_items methods in various REST handlers to use types.rest.GetItemsResult instead of types.rest.ManyItemsDictType for better clarity and type safety.
- Introduced UserServiceItem, GroupItem, TransportItem, PublicationItem, and ChangelogItem TypedDicts to standardize item representations across different handlers.
- Refactored AssignedService to AssignedUserService and updated related methods to reflect the new naming convention.
- Enhanced as_typed_dict utility function to convert models to TypedDicts, improving type safety in REST API responses.
- Cleaned up imports and ensured consistent use of typing annotations throughout the codebase.
This commit is contained in:
Adolfo Gómez García
2025-07-25 21:33:28 +02:00
parent 3d9bc55b1d
commit 6922d28537
22 changed files with 324 additions and 211 deletions

View File

@@ -114,7 +114,7 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
return ret_value
def get_items(self, parent: 'Model', item: typing.Optional[str]) -> types.rest.ManyItemsDictType:
def get_items(self, parent: 'Model', item: typing.Optional[str]) -> types.rest.GetItemsResult:
parent = ensure.is_instance(parent, models.Provider)
# Check what kind of access do we have to parent provider
perm = permissions.effective_permissions(self._user, parent)
@@ -335,7 +335,7 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
except Exception:
raise self.invalid_item_response() from None
def servicepools(self, parent: 'Model', item: str) -> types.rest.ManyItemsDictType:
def servicepools(self, parent: 'Model', item: str) -> types.rest.GetItemsResult:
parent = ensure.is_instance(parent, models.Provider)
service = parent.services.get(uuid=process_uuid(item))
logger.debug('Got parameters for servicepools: %s, %s', parent, item)