2023-05-12 02:32:50 +08:00
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
import strawberry # noqa
|
|
|
|
from api.gql.storage import types
|
2023-07-26 15:23:28 +08:00
|
|
|
from api.gql.permissions import IsAuthenticated
|
2023-05-12 02:32:50 +08:00
|
|
|
from apps.storage import models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class StorageQuery:
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def store_room_all(self, info) -> List[types.StoreRoomType]:
|
|
|
|
return await models.StoreRoom.all()
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def store_room_by_uid(
|
|
|
|
self, info, uid: str
|
|
|
|
) -> Optional[types.StoreRoomType]:
|
|
|
|
return await models.StoreRoom.get(uid=uid)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_locations(
|
|
|
|
self, info, store_room_uid: str
|
|
|
|
) -> List[types.StorageLocationType]:
|
|
|
|
return await models.StorageLocation.get_all(store_room_uid=store_room_uid)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_location_by_uid(
|
|
|
|
self, info, uid: str
|
|
|
|
) -> Optional[types.StorageLocationType]:
|
|
|
|
return await models.StorageLocation.get(uid=uid)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_sections(
|
|
|
|
self, info, storage_location_uid: str
|
|
|
|
) -> List[types.StorageSectionType]:
|
|
|
|
return await models.StorageLocation.get_all(
|
|
|
|
storage_location_uid=storage_location_uid
|
|
|
|
)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_section_by_uid(
|
|
|
|
self, info, uid: str
|
|
|
|
) -> Optional[types.StorageSectionType]:
|
|
|
|
return await models.StorageSection.get(uid=uid)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_containers(
|
|
|
|
self, info, storage_section_uid: str
|
|
|
|
) -> List[types.StorageContainerType]:
|
|
|
|
return await models.StorageContainer.get_all(
|
|
|
|
storage_section_uid=storage_section_uid
|
|
|
|
)
|
|
|
|
|
2023-07-26 15:23:28 +08:00
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
2023-05-12 02:32:50 +08:00
|
|
|
async def storage_container_by_uid(
|
|
|
|
self, info, uid: str
|
|
|
|
) -> Optional[types.StorageContainerType]:
|
|
|
|
return await models.StorageContainer.get(uid=uid)
|