Skip to content

Commit 72395b2

Browse files
committed
add metadata, sectors and tags to usecase type
1 parent dfffb06 commit 72395b2

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

api/types/type_usecase.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from strawberry import Info, auto
66
from strawberry.enum import EnumType
77

8-
from api.models import Organization, UseCase
8+
from api.models import Organization, UseCase, UseCaseMetadata
99
from api.types.base_type import BaseType
10-
from api.types.type_dataset import TypeDataset
10+
from api.types.type_dataset import TypeDataset, TypeTag
1111
from api.types.type_organization import TypeOrganization
12+
from api.types.type_sector import TypeSector
13+
from api.types.type_usecase_metadata import TypeUseCaseMetadata
1214
from api.utils.enums import UseCaseStatus
1315

1416
use_case_status: EnumType = strawberry.enum(UseCaseStatus)
@@ -72,3 +74,36 @@ def publishers(self) -> Optional[List["TypeOrganization"]]:
7274
return TypeOrganization.from_django_list(queryset)
7375
except Exception:
7476
return []
77+
78+
@strawberry.field
79+
def sectors(self) -> Optional[List["TypeSector"]]:
80+
"""Get sectors associated with this use case."""
81+
try:
82+
queryset = self.sectors.all() # type: ignore
83+
if not queryset.exists():
84+
return []
85+
return TypeSector.from_django_list(queryset)
86+
except Exception:
87+
return []
88+
89+
@strawberry.field
90+
def tags(self) -> Optional[List["TypeTag"]]:
91+
"""Get tags associated with this use case."""
92+
try:
93+
queryset = self.tags.all() # type: ignore
94+
if not queryset.exists():
95+
return []
96+
return TypeTag.from_django_list(queryset)
97+
except Exception:
98+
return []
99+
100+
@strawberry.field
101+
def metadata(self) -> Optional[List["TypeUseCaseMetadata"]]:
102+
"""Get metadata associated with this use case."""
103+
try:
104+
queryset = UseCaseMetadata.objects.filter(usecase=self) # type: ignore
105+
if not queryset.exists():
106+
return []
107+
return TypeUseCaseMetadata.from_django_list(queryset)
108+
except Exception:
109+
return []

api/types/type_usecase_metadata.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import strawberry_django
2+
3+
from api.models import UseCaseMetadata
4+
from api.types.base_type import BaseType
5+
from api.types.type_metadata import TypeMetadata
6+
7+
8+
@strawberry_django.type(UseCaseMetadata, fields="__all__")
9+
class TypeUseCaseMetadata(BaseType):
10+
metadata_item: TypeMetadata

0 commit comments

Comments
 (0)