Skip to content

Commit

Permalink
Merge pull request #161 from ael-code/api_delete
Browse files Browse the repository at this point in the history
[rest_api] exposed delete_volume and delete_attachment functions
  • Loading branch information
leonaard committed Jun 14, 2015
2 parents 7059036 + dda7cb1 commit 2ffa1f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions webant/api/blueprint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def __init__(self, message, http_code, err_code=None, details=None):
def __str__(self):
return "http_code: {}, err_code: {}, message: '{}', details: '{}'".format(self.http_code, self.err_code, self.message, self.details)

def make_success_response(message, http_code=200):
response = jsonify({'code': http_code, 'message': message})
response.status_code = http_code
return response

api = Blueprint('api', __name__)

Expand Down Expand Up @@ -74,6 +78,14 @@ def get_volume(volumeID):
raise ApiError("volume not found", 404, details=str(e))
return jsonify({'data': volume})

@api.route('/volumes/<volumeID>', methods=['DELETE'])
def delete_volume(volumeID):
try:
current_app.archivant.delete_volume(volumeID)
except NotFoundException, e:
raise ApiError("volume not found", 404, details=str(e))
return make_success_response("volume has been successfully deleted")

@api.route('/volumes/<volumeID>/attachments/', methods=['GET'])
def get_attachments(volumeID):
try:
Expand All @@ -90,6 +102,14 @@ def get_attachment(volumeID, attachmentID):
raise ApiError("attachment not found", 404, details=str(e))
return jsonify({'data': att})

@api.route('/volumes/<volumeID>/attachments/<attachmentID>', methods=['DELETE'])
def delete_attachment(volumeID, attachmentID):
try:
current_app.archivant.delete_attachments(volumeID, [attachmentID])
except NotFoundException, e:
raise ApiError("attachment not found", 404, details=str(e))
return make_success_response("attachment has been successfully deleted")

@api.route('/volumes/<volumeID>/attachments/<attachmentID>/file', methods=['GET'])
def get_file(volumeID, attachmentID):
try:
Expand Down

0 comments on commit 2ffa1f7

Please sign in to comment.