From 17e741280d89cb7240a4f16abbec66ecdc42a717 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 20 Jun 2022 16:44:25 -0400 Subject: [PATCH] added api endpoint to delete a process instance w/ burnettk --- src/spiffworkflow_backend/api.yml | 33 +++++++++++++++++++ .../routes/process_api_blueprint.py | 20 ++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/spiffworkflow_backend/api.yml b/src/spiffworkflow_backend/api.yml index bed7fbfb..e0571188 100755 --- a/src/spiffworkflow_backend/api.yml +++ b/src/spiffworkflow_backend/api.yml @@ -325,6 +325,39 @@ paths: items: $ref: "#/components/schemas/Workflow" + /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}: + parameters: + - name: process_group_id + in: path + required: true + description: The unique id of an existing process group + schema: + type: string + - name: process_model_id + in: path + required: true + description: The unique id of an existing workflow specification. + schema: + type: string + - name: process_instance_id + in: path + required: true + description: The unique id of an existing process instance. + schema: + type: integer + delete: + operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_delete + summary: Deletes a single process group + tags: + - Process Groups + responses: + "200": + description: The process instance was deleted. + content: + application/json: + schema: + $ref: "#components/schemas/OkTrue" + /process-models/{process_group_id}/{process_model_id}/process-instances/report: parameters: - name: process_group_id diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index 19ef1764..bc42f2e6 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -6,6 +6,7 @@ from flask import Blueprint from flask import g from flask import Response from flask_bpmn.api.api_error import ApiError +from flask_bpmn.models.db import db from spiffworkflow_backend.models.file import FileSchema from spiffworkflow_backend.models.file import FileType @@ -251,7 +252,7 @@ def process_instance_list(process_group_id, process_model_id, page=1, per_page=1 if process_model is None: raise ( ApiError( - code="process_mode_cannot_be_found", + code="process_model_cannot_be_found", message=f"Process model cannot be found: {process_model_id}", status_code=400, ) @@ -282,6 +283,23 @@ def process_instance_list(process_group_id, process_model_id, page=1, per_page=1 return Response(json.dumps(response_json), status=200, mimetype="application/json") +def process_instance_delete(process_group_id, process_model_id, process_instance_id): + """Create_process_instance.""" + process_instance = ProcessInstanceModel.query.filter_by(id=process_instance_id).first() + if process_instance is None: + raise ( + ApiError( + code="process_instance_cannot_be_found", + message=f"Process instance cannot be found: {process_instance_id}", + status_code=400, + ) + ) + + db.session.delete(process_instance) + db.session.commit() + return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") + + def process_instance_report(process_group_id, process_model_id, page=1, per_page=100): """Process_instance_list.""" process_model = ProcessModelService().get_process_model(