diff --git a/selfprivacy_api/graphql/common_types/service.py b/selfprivacy_api/graphql/common_types/service.py index c9cf50e..fc9f205 100644 --- a/selfprivacy_api/graphql/common_types/service.py +++ b/selfprivacy_api/graphql/common_types/service.py @@ -3,14 +3,44 @@ import typing import strawberry from selfprivacy_api.graphql.common_types.dns import DnsRecord -from selfprivacy_api.graphql.common_types.storage_usage import ( - StorageUsageInterface, - StorageVolume, -) from selfprivacy_api.services import get_service_by_id, get_services_by_location from selfprivacy_api.services import Service as ServiceInterface from selfprivacy_api.utils.block_devices import BlockDevices +def get_usages(root: "StorageVolume") -> list["StorageUsageInterface"]: + """Get usages of a volume""" + return [ + ServiceStorageUsage( + service=service_to_graphql_service(service), + title=service.get_display_name(), + used_space=str(service.get_storage_usage()), + volume=get_volume_by_id(service.get_location()), + ) + for service in get_services_by_location(root.name) + ] + +@strawberry.type +class StorageVolume: + """Stats and basic info about a volume or a system disk.""" + + total_space: str + free_space: str + used_space: str + root: bool + name: str + model: typing.Optional[str] + serial: typing.Optional[str] + type: str + usages: list["StorageUsageInterface"] = strawberry.field(resolver=get_usages) + + + +@strawberry.interface +class StorageUsageInterface: + used_space: str + volume: typing.Optional[StorageVolume] + title: str + @strawberry.type class ServiceStorageUsage(StorageUsageInterface): diff --git a/selfprivacy_api/graphql/common_types/storage_usage.py b/selfprivacy_api/graphql/common_types/storage_usage.py deleted file mode 100644 index f45966e..0000000 --- a/selfprivacy_api/graphql/common_types/storage_usage.py +++ /dev/null @@ -1,24 +0,0 @@ -import typing -import strawberry - - -@strawberry.type -class StorageVolume: - """Stats and basic info about a volume or a system disk.""" - - total_space: str - free_space: str - used_space: str - root: bool - name: str - model: typing.Optional[str] - serial: typing.Optional[str] - type: str - usages: list["StorageUsageInterface"] - - -@strawberry.interface -class StorageUsageInterface: - used_space: str - volume: typing.Optional[StorageVolume] - title: str diff --git a/selfprivacy_api/graphql/queries/storage.py b/selfprivacy_api/graphql/queries/storage.py index 73b9a8d..273b6a7 100644 --- a/selfprivacy_api/graphql/queries/storage.py +++ b/selfprivacy_api/graphql/queries/storage.py @@ -7,7 +7,7 @@ from selfprivacy_api.graphql.common_types.service import ( service_to_graphql_service, get_volume_by_id, ) -from selfprivacy_api.graphql.common_types.storage_usage import ( +from selfprivacy_api.graphql.common_types.service import ( StorageVolume, ) from selfprivacy_api.services import get_services_by_location @@ -33,15 +33,6 @@ class Storage: model=volume.model, serial=volume.serial, type=volume.type, - usages=[ - ServiceStorageUsage( - service=service_to_graphql_service(service), - title=service.get_display_name(), - used_space=str(service.get_storage_usage()), - volume=get_volume_by_id(service.get_location()), - ) - for service in get_services_by_location(volume.name) - ], ) for volume in BlockDevices().get_block_devices() ]