diff --git a/Ghost_in_the_Shell/client_folder_react_app/ethisim/src/components/EditorComponents/IssueCoverageMatrixComponents/IssueCoverageMatrixPage.js b/Ghost_in_the_Shell/client_folder_react_app/ethisim/src/components/EditorComponents/IssueCoverageMatrixComponents/IssueCoverageMatrixPage.js index f23325b6..7a41f5b4 100644 --- a/Ghost_in_the_Shell/client_folder_react_app/ethisim/src/components/EditorComponents/IssueCoverageMatrixComponents/IssueCoverageMatrixPage.js +++ b/Ghost_in_the_Shell/client_folder_react_app/ethisim/src/components/EditorComponents/IssueCoverageMatrixComponents/IssueCoverageMatrixPage.js @@ -136,7 +136,8 @@ export default function ICMatrix({ scenario_ID }) { var config = { method: 'put', //url: baseURL + '/multi_stake?scenario=' + scenario_ID, - url: baseURL + '/multi_stake?scenario=' + scenario_ID, + //url: baseURL + '/multi_stake?scenario=' + scenario_ID, + url: baseURL + '/stakeholder', headers: { 'Content-Type': 'application/json', }, diff --git a/moral_kombat_backend/lead/tables/views.py b/moral_kombat_backend/lead/tables/views.py index 868f5e4e..225ba3e7 100644 --- a/moral_kombat_backend/lead/tables/views.py +++ b/moral_kombat_backend/lead/tables/views.py @@ -346,6 +346,35 @@ class IssuesViewSet(viewsets.ModelViewSet): # filter_backends = [DjangoFilterBackend] # filterset_fields = ['scenario_id', "name"] + def create(self, request, *args, **kwargs): + + serializer = IssuesSerializer(data=request.data) + + if serializer.is_valid(): + + serializer.save() + + scenarioID = serializer.data['scenario_id'] + issueID = serializer.data['issue'] + + stakeholders = stakeholders.objects.filter(scenario=scenarioID).values() + + for stakeholder in stakeholders: + newCoverage = {} + newCoverage['stakeholder'] = stakeholder['stakeholder'] + newCoverage['issue'] = issueID + newCoverage['coverage_score'] = 0 + + coverageSerial = coverageSerializer(data=newCoverage) + if coverageSerial.is_valid(): + coverageSerial.save() + else: + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + return Response(serializer.data, status=status.HTTP_201_CREATED) + + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class Action_pageViewSet(viewsets.ModelViewSet): queryset = action_page.objects.all()