def delete_template(template_id): logger.info(f'Deleting template id {template_id}') resp = templates_dynamodb.delete_template(template_id) if resp: templates_s3.delete_file(Template.from_dict(resp)) return '', http.HTTPStatus.NO_CONTENT else: return jsonify({'error': 'The template does not exists' }), http.HTTPStatus.NOT_FOUND
def create_template(): try: logger.info(f'Creating a new template for request {request.json}') request.json['id'] = str(uuid4())[:8] template = Template.from_dict(request.json) except (KeyError, TypeError): logger.exception('Error creating template') return jsonify({'error': 'Please provide at least a valid id' }), http.HTTPStatus.BAD_REQUEST if templates_dynamodb.add_template(template) is None: return jsonify({'error': 'The template path already exists' }), http.HTTPStatus.BAD_REQUEST return jsonify(template)