Skip to content
Snippets Groups Projects

WS-85: Delete capability request REST endpoint

Merged Nathan Hertz requested to merge WS-85-delete-capability-request-rest-endpoint into main
1 unresolved thread
5 files
+ 174
6
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -4,13 +4,12 @@
File containing definitions for the other half of the capability side of the Workspaces REST API,
concerning capability requests
"""
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound, HTTPPreconditionFailed
from pyramid.request import Request
from pyramid.response import Response
from pyramid.view import view_config
from workspaces.capability.schema import CapabilityRequest
@view_config(route_name="view_capability_request", renderer="json")
def view_capability_request(request: Request) -> Response:
@@ -19,7 +18,7 @@ def view_capability_request(request: Request) -> Response:
URL: capability/{capability_name}/request/{request_id}
:param request: GET request
:return: Response with JSON-formatted capability request info if found
:return: 200 OK response with JSON-formatted capability request info if found
or 404 response (HTTPNotFound)
"""
capability_request = request.capability_info.lookup_capability_request(
@@ -42,7 +41,7 @@ def create_capability_request(request: Request) -> Response:
URL: capability/{capability_name}/request/create
:param request: POST request, expecting JSON parameter "parameters"
:return: Response with JSON-formatted info of newly created capability request
:return: 200 OK response with JSON-formatted info of newly created capability request
or 400 response (HTTPBadRequest) if expected parameters not given
or 412 response (HTTPPreconditionFailed) if capability with given name does not exist and thus cannot be
requested
@@ -92,7 +91,7 @@ def submit_capability_request(request: Request) -> Response:
URL: capability/{capability_name}/request/{request_id}/submit
:param request: POST request
:return: Response with
:return: 200 OK response
or 412 response (HTTPPreconditionFailed) if capability request with given ID does not exist and thus cannot be
submitted
"""
@@ -102,8 +101,41 @@ def submit_capability_request(request: Request) -> Response:
if not capability_request:
# Capability request not found
does_not_exist_msg = f"Capability request for {capability_name} with ID {request_id} does not exist. Cannot submit request."
does_not_exist_msg = f"Capability request for {capability_name} with ID {request_id} does not exist. Cannot submit."
return HTTPPreconditionFailed(detail=does_not_exist_msg)
else:
execution = request.capability_service.run_capability(capability_request)
return Response(json_body=execution.__json__())
@view_config(route_name="delete_capability_request", renderer="json")
def delete_capability_request(request: Request) -> Response:
"""
Pyramid view that accepts a request to delete a capability request from the face of the archive
URL: capability/{capability_name}/request/{request_id}
:param request: DELETE request
:return: 200 OK response
or 412 response (HTTPPreconditionFailed) if capability request with given ID does not exist and thus cannot be
deleted
or 400 response (HTTPBadRequest) if capability request with given ID cannot be deleted
"""
capability_name = request.matchdict["capability_name"]
request_id = request.matchdict["request_id"]
capability_request = request.capability_info.lookup_capability_request(request_id)
if not capability_request:
# Capability request not found
does_not_exist_msg = f"Capability request for {capability_name} with ID {request_id} does not exist. Cannot delete."
return HTTPPreconditionFailed(detail=does_not_exist_msg)
else:
rows_deleted = request.capability_info.delete_capability_request(request_id)
if rows_deleted == -1:
bad_request_msg = (
f"Capability request for {capability_name} with ID {request_id} cannot be deleted;",
f"it has existing executions.",
)
return HTTPBadRequest(detail=bad_request_msg)
return Response(
body=f"Capability request for {capability_name} with ID {request_id} successfully deleted."
)
Loading