From 4c8b7ae4fb4e4b81d60c62b63134b0e27780388b Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 8 Apr 2021 07:59:52 +0200
Subject: [PATCH] TMSS-216: added rest endpoint for
 create_cleanuptask_for_scheduling_unit_blueprint action

---
 .../src/tmss/tmssapp/viewsets/specification.py      | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
index 6b5c19e704e..19e5818a634 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
@@ -810,6 +810,19 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet):
                         status=status.HTTP_200_OK)
 
 
+    @swagger_auto_schema(responses={201: "This SchedulingUnitBlueprint, with references to the created Cleanup TaskBlueprints.",
+                                    403: 'forbidden'},
+                         operation_description="Create a cleanup task for this scheduling unit.")
+    @action(methods=['get'], detail=True, url_name="create_cleanuptask", name="Create a cleanup task for this scheduling unit")
+    def create_cleanuptask_for_scheduling_unit_blueprint(self, request, pk=None):
+        scheduling_unit_blueprint = get_object_or_404(models.SchedulingUnitBlueprint, pk=pk)
+        scheduling_unit_blueprint = create_cleanuptask_for_scheduling_unit_blueprint(scheduling_unit_blueprint)
+
+        # return a response with the new serialized scheduling_unit_blueprint (with references to the created task_blueprint and subtask)
+        return Response(serializers.SchedulingUnitBlueprintSerializer(scheduling_unit_blueprint, context={'request':request}).data,
+                        status=status.HTTP_201_CREATED)
+
+
 class SchedulingUnitBlueprintExtendedViewSet(SchedulingUnitBlueprintViewSet):
     serializer_class = serializers.SchedulingUnitBlueprintExtendedSerializer
 
-- 
GitLab