Skip to content

Commit b62e507

Browse files
committed
fix return types of all dashboard mutations
1 parent a2b75a6 commit b62e507

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

api/schema/usecase_dashboard_schema.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from strawberry_django.pagination import OffsetPaginationInput
99

1010
from api.models import UseCase, UseCaseDashboard
11-
from api.schema.base_mutation import BaseMutation
11+
from api.schema.base_mutation import BaseMutation, MutationResponse
1212
from api.types.type_usecase_dashboard import (
1313
TypeUseCaseDashboard,
1414
UseCaseDashboardFilter,
@@ -62,7 +62,7 @@ class Mutation:
6262
)
6363
def add_usecase_dashboards(
6464
self, info: Info, input: AddUseCaseDashboardsInput
65-
) -> List[TypeUseCaseDashboard]:
65+
) -> MutationResponse[List[TypeUseCaseDashboard]]:
6666
"""Add multiple dashboards to a usecase."""
6767
try:
6868
# Check if usecase exists
@@ -78,7 +78,9 @@ def add_usecase_dashboards(
7878
)
7979
created_dashboards.append(dashboard)
8080

81-
return TypeUseCaseDashboard.from_django_list(created_dashboards)
81+
return MutationResponse.success_response(
82+
TypeUseCaseDashboard.from_django_list(created_dashboards)
83+
)
8284
except UseCase.DoesNotExist:
8385
raise Exception(f"Usecase with ID {input.usecase_id} does not exist")
8486
except Exception as e:
@@ -103,7 +105,7 @@ def add_usecase_dashboard(
103105
usecase_id: int,
104106
name: Optional[str] = "",
105107
link: Optional[str] = "",
106-
) -> TypeUseCaseDashboard:
108+
) -> MutationResponse[TypeUseCaseDashboard]:
107109
"""Add a usecase dashboard."""
108110
try:
109111
# Check if usecase exists
@@ -116,7 +118,9 @@ def add_usecase_dashboard(
116118
usecase=usecase,
117119
)
118120

119-
return TypeUseCaseDashboard.from_django(dashboard)
121+
return MutationResponse.success_response(
122+
TypeUseCaseDashboard.from_django(dashboard)
123+
)
120124
except UseCase.DoesNotExist:
121125
raise Exception(f"Usecase with ID {usecase_id} does not exist")
122126
except Exception as e:
@@ -136,14 +140,16 @@ def add_usecase_dashboard(
136140
)
137141
def update_usecase_dashboard(
138142
self, info: Info, id: str, name: Optional[str] = "", link: Optional[str] = ""
139-
) -> TypeUseCaseDashboard:
143+
) -> MutationResponse[TypeUseCaseDashboard]:
140144
"""Update a usecase dashboard."""
141145
try:
142146
dashboard = UseCaseDashboard.objects.get(id=id)
143147
dashboard.name = name or dashboard.name
144148
dashboard.link = link or dashboard.link
145149
dashboard.save()
146-
return TypeUseCaseDashboard.from_django(dashboard)
150+
return MutationResponse.success_response(
151+
TypeUseCaseDashboard.from_django(dashboard)
152+
)
147153
except UseCaseDashboard.DoesNotExist:
148154
raise Exception(f"Dashboard with ID {id} does not exist")
149155
except Exception as e:
@@ -161,12 +167,12 @@ def update_usecase_dashboard(
161167
},
162168
},
163169
)
164-
def delete_usecase_dashboard(self, info: Info, id: int) -> bool:
170+
def delete_usecase_dashboard(self, info: Info, id: int) -> MutationResponse[bool]:
165171
"""Delete a usecase dashboard."""
166172
try:
167173
dashboard = UseCaseDashboard.objects.get(id=id)
168174
dashboard.delete()
169-
return True
175+
return MutationResponse.success_response(True)
170176
except UseCaseDashboard.DoesNotExist:
171177
raise Exception(f"Dashboard with ID {id} does not exist")
172178
except Exception as e:

0 commit comments

Comments
 (0)