def delete(self, path: str) -> Response: """ Method executed for DELETE requests. Used to delete a non-collection class. :param path - Path for Item ( Specified in APIDoc @id) """ auth_response = check_authentication_response() if isinstance(auth_response, Response): return auth_response endpoint_ = checkEndpoint("DELETE", path) if endpoint_['method']: # No Delete Operation for collections if path in get_doc().parsed_classes and path + \ "Collection" not in get_doc().collections: try: class_type = get_doc().parsed_classes[path]['class'].title crud.delete_single(class_type, session=get_session()) response = {"message": "Object successfully deleted"} return set_response_headers(jsonify(response)) except (ClassNotFound, InstanceNotFound) as e: status_code, message = e.get_HTTP() return set_response_headers(jsonify(message), status_code=status_code) abort(endpoint_['status'])
def on_delete(self, req, resp, type_: str): """ Method executed for DELETE requests. Used to delete a non-collection class. :param type_ - Item type """ if get_authentication(resp): if req.auth is None: return failed_authentication(resp) else: try: auth = check_authorization(req, get_session(resp)) if auth is False: return failed_authentication(resp) except Exception as e: status_code, message = e.get_HTTP() # type: ignore resp.media = message return set_response_headers(resp, status_code=status_code) endpoint_ = checkEndpoint(resp, "DELETE", type_) if endpoint_['method']: # No Delete Operation for collections if type_ in get_doc(resp).parsed_classes and type_ + "Collection" not in get_doc(resp).collections: try: crud.delete_single(type_, session=get_session(resp)) response = {"message": "Object successfully deleted"} resp.media = response return set_response_headers(resp) except Exception as e: status_code, message = e.get_HTTP() resp.media = message return set_response_headers(resp, status_code=status_code)
def delete(self, type_: str) -> Response: """Delete a non Collection class item.""" if get_authentication(): if request.authorization is None: return failed_authentication() else: try: auth = check_authorization(request, get_session()) if auth is False: return failed_authentication() except Exception as e: status_code, message = e.get_HTTP() # type: ignore return set_response_headers(jsonify(message), status_code=status_code) endpoint_ = checkEndpoint("DELETE", type_) if endpoint_['method']: # No Delete Operation for collections if type_ in get_doc( ).parsed_classes and type_ + "Collection" not in get_doc( ).collections: try: crud.delete_single(type_, session=get_session()) response = {"message": "Object successfully deleted"} return set_response_headers(jsonify(response)) except Exception as e: status_code, message = e.get_HTTP() # type: ignore return set_response_headers(jsonify(message), status_code=status_code) abort(endpoint_['status'])
def delete(self, type_: str) -> Response: """ Method executed for DELETE requests. Used to delete a non-collection class. :param type_ - Item type """ auth_response = check_authentication_response() if type(auth_response) == Response: return auth_response endpoint_ = checkEndpoint("DELETE", type_) if endpoint_['method']: # No Delete Operation for collections if type_ in get_doc( ).parsed_classes and type_ + "Collection" not in get_doc( ).collections: try: crud.delete_single(type_, session=get_session()) response = {"message": "Object successfully deleted"} return set_response_headers(jsonify(response)) except Exception as e: status_code, message = e.get_HTTP() # type: ignore return set_response_headers(jsonify(message), status_code=status_code) abort(endpoint_['status'])