|
5 | 5 | from strawberry import Info, auto |
6 | 6 | from strawberry.enum import EnumType |
7 | 7 |
|
8 | | -from api.models import Organization, UseCase |
| 8 | +from api.models import Organization, UseCase, UseCaseMetadata |
9 | 9 | from api.types.base_type import BaseType |
10 | | -from api.types.type_dataset import TypeDataset |
| 10 | +from api.types.type_dataset import TypeDataset, TypeTag |
11 | 11 | from api.types.type_organization import TypeOrganization |
| 12 | +from api.types.type_sector import TypeSector |
| 13 | +from api.types.type_usecase_metadata import TypeUseCaseMetadata |
12 | 14 | from api.utils.enums import UseCaseStatus |
13 | 15 |
|
14 | 16 | use_case_status: EnumType = strawberry.enum(UseCaseStatus) |
@@ -72,3 +74,36 @@ def publishers(self) -> Optional[List["TypeOrganization"]]: |
72 | 74 | return TypeOrganization.from_django_list(queryset) |
73 | 75 | except Exception: |
74 | 76 | 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 [] |
0 commit comments