@@ -62,7 +62,7 @@ class Mutation:
6262 )
6363 def add_usecase_dashboards (
6464 self , info : Info , input : AddUseCaseDashboardsInput
65- ) -> UseCaseDashboardMutationResponse :
65+ ) -> List [ TypeUseCaseDashboard ] :
6666 """Add multiple dashboards to a usecase."""
6767 try :
6868 # Check if usecase exists
@@ -78,18 +78,77 @@ def add_usecase_dashboards(
7878 )
7979 created_dashboards .append (dashboard )
8080
81- return UseCaseDashboardMutationResponse (
82- dashboards = [
83- TypeUseCaseDashboard .from_django (d ) for d in created_dashboards
84- ],
85- success = True ,
86- message = f"Added { len (created_dashboards )} dashboards to usecase" ,
87- )
81+ return TypeUseCaseDashboard .from_django_list (created_dashboards )
8882 except UseCase .DoesNotExist :
8983 raise Exception (f"Usecase with ID { input .usecase_id } does not exist" )
9084 except Exception as e :
9185 raise Exception (f"Failed to add dashboards: { str (e )} " )
9286
87+ @strawberry .mutation
88+ @BaseMutation .mutation (
89+ permission_classes = [IsAuthenticated ],
90+ trace_name = "add_usecase_dashboard" ,
91+ trace_attributes = {"component" : "usecase_dashboard" },
92+ track_activity = {
93+ "verb" : "created" ,
94+ "get_data" : lambda result , ** kwargs : {
95+ "usecase_id" : str (kwargs .get ("usecase_id" )),
96+ "dashboard_id" : str (kwargs .get ("id" )),
97+ },
98+ },
99+ )
100+ def add_usecase_dashboard (
101+ self ,
102+ info : Info ,
103+ usecase_id : int ,
104+ name : Optional [str ] = "" ,
105+ link : Optional [str ] = "" ,
106+ ) -> TypeUseCaseDashboard :
107+ """Add a usecase dashboard."""
108+ try :
109+ # Check if usecase exists
110+ usecase = UseCase .objects .get (id = usecase_id )
111+
112+ # Create dashboard
113+ dashboard = UseCaseDashboard .objects .create (
114+ name = name or "" ,
115+ link = link or "" ,
116+ usecase = usecase ,
117+ )
118+
119+ return TypeUseCaseDashboard .from_django (dashboard )
120+ except UseCase .DoesNotExist :
121+ raise Exception (f"Usecase with ID { usecase_id } does not exist" )
122+ except Exception as e :
123+ raise Exception (f"Failed to add dashboard: { str (e )} " )
124+
125+ @strawberry .mutation
126+ @BaseMutation .mutation (
127+ permission_classes = [IsAuthenticated ],
128+ trace_name = "update_usecase_dashboard" ,
129+ trace_attributes = {"component" : "usecase_dashboard" },
130+ track_activity = {
131+ "verb" : "updated" ,
132+ "get_data" : lambda result , ** kwargs : {
133+ "dashboard_id" : str (kwargs .get ("id" )),
134+ },
135+ },
136+ )
137+ def update_usecase_dashboard (
138+ self , info : Info , id : str , name : Optional [str ] = "" , link : Optional [str ] = ""
139+ ) -> TypeUseCaseDashboard :
140+ """Update a usecase dashboard."""
141+ try :
142+ dashboard = UseCaseDashboard .objects .get (id = id )
143+ dashboard .name = name or dashboard .name
144+ dashboard .link = link or dashboard .link
145+ dashboard .save ()
146+ return TypeUseCaseDashboard .from_django (dashboard )
147+ except UseCaseDashboard .DoesNotExist :
148+ raise Exception (f"Dashboard with ID { id } does not exist" )
149+ except Exception as e :
150+ raise Exception (f"Failed to update dashboard: { str (e )} " )
151+
93152 @strawberry .mutation
94153 @BaseMutation .mutation (
95154 permission_classes = [IsAuthenticated ],
@@ -102,17 +161,12 @@ def add_usecase_dashboards(
102161 },
103162 },
104163 )
105- def delete_usecase_dashboard (
106- self , info : Info , id : int
107- ) -> UseCaseDashboardMutationResponse :
164+ def delete_usecase_dashboard (self , info : Info , id : int ) -> bool :
108165 """Delete a usecase dashboard."""
109166 try :
110167 dashboard = UseCaseDashboard .objects .get (id = id )
111168 dashboard .delete ()
112- return UseCaseDashboardMutationResponse (
113- success = True ,
114- message = f"Dashboard with ID { id } deleted successfully" ,
115- )
169+ return True
116170 except UseCaseDashboard .DoesNotExist :
117171 raise Exception (f"Dashboard with ID { id } does not exist" )
118172 except Exception as e :
0 commit comments