@@ -64,6 +64,7 @@ class UseCaseInputPartial:
6464 """Input type for use case updates."""
6565
6666 id : str
67+ title : auto
6768 slug : auto
6869 summary : auto
6970
@@ -241,7 +242,7 @@ class Mutation:
241242 """Mutations for use cases."""
242243
243244 create_use_case : TypeUseCase = mutations .create (UseCaseInput )
244- update_use_case : TypeUseCase = mutations .update (UseCaseInputPartial , key_attr = "id" )
245+ # update_use_case: TypeUseCase = mutations.update(UseCaseInputPartial, key_attr="id")
245246
246247 @strawberry_django .mutation (
247248 handle_django_errors = True ,
@@ -326,12 +327,41 @@ def add_update_usecase_metadata(
326327 except UseCase .DoesNotExist :
327328 raise ValueError (f"UseCase with ID { usecase_id } does not exist." )
328329
330+ if usecase .status != UseCaseStatus .DRAFT :
331+ raise ValueError (f"UseCase with ID { usecase_id } is not in draft status." )
332+
329333 if update_metadata_input .tags is not None :
330334 _update_usecase_tags (usecase , update_metadata_input .tags )
331335 _add_update_usecase_metadata (usecase , metadata_input )
332336 _update_usecase_sectors (usecase , update_metadata_input .sectors )
333337 return TypeUseCase .from_django (usecase )
334338
339+ @strawberry_django .mutation (handle_django_errors = True )
340+ @trace_resolver (
341+ name = "update_use_case" ,
342+ attributes = {"component" : "usecase" , "operation" : "mutation" },
343+ )
344+ def update_use_case (
345+ self , info : Info , use_case_input_partial : UseCaseInputPartial
346+ ) -> TypeUseCase :
347+ usecase_id = use_case_input_partial .id
348+ try :
349+ usecase = UseCase .objects .get (id = usecase_id )
350+ except UseCase .DoesNotExist :
351+ raise ValueError (f"UseCase with ID { usecase_id } does not exist." )
352+
353+ if usecase .status != UseCaseStatus .DRAFT :
354+ raise ValueError (f"UseCase with ID { usecase_id } is not in draft status." )
355+
356+ if use_case_input_partial .title == "" :
357+ raise ValueError ("Title cannot be empty." )
358+ if use_case_input_partial .title is not None :
359+ usecase .title = use_case_input_partial .title
360+ if use_case_input_partial .summary is not None :
361+ usecase .summary = use_case_input_partial .summary
362+ usecase .save ()
363+ return TypeUseCase .from_django (usecase )
364+
335365 @strawberry_django .mutation (
336366 handle_django_errors = False ,
337367 extensions = [
@@ -371,6 +401,9 @@ def add_dataset_to_use_case(
371401 except UseCase .DoesNotExist :
372402 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
373403
404+ if use_case .status != UseCaseStatus .DRAFT :
405+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
406+
374407 use_case .datasets .add (dataset )
375408 use_case .save ()
376409 return TypeUseCase .from_django (use_case )
@@ -384,12 +417,13 @@ def remove_dataset_from_use_case(
384417 dataset = Dataset .objects .get (id = dataset_id )
385418 except Dataset .DoesNotExist :
386419 raise ValueError (f"Dataset with ID { dataset_id } does not exist." )
387-
388420 try :
389421 use_case = UseCase .objects .get (id = use_case_id )
390422 except UseCase .DoesNotExist :
391423 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
392424
425+ if use_case .status != UseCaseStatus .DRAFT :
426+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
393427 use_case .datasets .remove (dataset )
394428 use_case .save ()
395429 return TypeUseCase .from_django (use_case )
@@ -409,6 +443,9 @@ def update_usecase_datasets(
409443 except UseCase .DoesNotExist :
410444 raise ValueError (f"Use Case with ID { use_case_id } doesn't exist" )
411445
446+ if use_case .status != UseCaseStatus .DRAFT :
447+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
448+
412449 use_case .datasets .set (datasets )
413450 use_case .save ()
414451 return TypeUseCase .from_django (use_case )
@@ -487,6 +524,9 @@ def add_contributor_to_use_case(
487524 except UseCase .DoesNotExist :
488525 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
489526
527+ if use_case .status != UseCaseStatus .DRAFT :
528+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
529+
490530 use_case .contributors .add (user )
491531 use_case .save ()
492532 return TypeUseCase .from_django (use_case )
@@ -511,6 +551,9 @@ def remove_contributor_from_use_case(
511551 except UseCase .DoesNotExist :
512552 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
513553
554+ if use_case .status != UseCaseStatus .DRAFT :
555+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
556+
514557 use_case .contributors .remove (user )
515558 use_case .save ()
516559 return TypeUseCase .from_django (use_case )
@@ -545,6 +588,9 @@ def update_usecase_contributors(
545588 except UseCase .DoesNotExist :
546589 raise ValueError (f"Use Case with ID { use_case_id } doesn't exist" )
547590
591+ if use_case .status != UseCaseStatus .DRAFT :
592+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
593+
548594 use_case .contributors .set (users )
549595 use_case .save ()
550596 return TypeUseCase .from_django (use_case )
@@ -569,6 +615,9 @@ def add_supporting_organization_to_use_case(
569615 except UseCase .DoesNotExist :
570616 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
571617
618+ if use_case .status != UseCaseStatus .DRAFT :
619+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
620+
572621 # Create or get the relationship
573622 relationship , created = UseCaseOrganizationRelationship .objects .get_or_create (
574623 usecase = use_case ,
@@ -621,6 +670,9 @@ def add_partner_organization_to_use_case(
621670 except UseCase .DoesNotExist :
622671 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
623672
673+ if use_case .status != UseCaseStatus .DRAFT :
674+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
675+
624676 # Create or get the relationship
625677 relationship , created = UseCaseOrganizationRelationship .objects .get_or_create (
626678 usecase = use_case ,
@@ -691,6 +743,9 @@ def update_usecase_organization_relationships(
691743 except UseCase .DoesNotExist :
692744 raise ValueError (f"UseCase with ID { use_case_id } does not exist." )
693745
746+ if use_case .status != UseCaseStatus .DRAFT :
747+ raise ValueError (f"UseCase with ID { use_case_id } is not in draft status." )
748+
694749 # Clear existing relationships
695750 UseCaseOrganizationRelationship .objects .filter (usecase = use_case ).delete ()
696751
0 commit comments