def edit_bucket(current_user, bucket_id):
"""
Validate the bucket Id. Also check for the name attribute in the json payload.
If the name exists update the bucket with the new name.
:param current_user: Current User
:param bucket_id: Bucket Id
:return: Http Json response
"""
if request.content_type == 'application/json':
data = request.get_json()
name = data.get('name')
if name:
try:
int(bucket_id)
except ValueError:
return response('failed', 'Please provide a valid Bucket Id', 400)
user_bucket = User.get_by_id(current_user.id).buckets.filter_by(id=bucket_id).first()
if user_bucket:
user_bucket.update(name)
return response_for_created_bucket(user_bucket, 201)
return response('failed', 'The Bucket with Id ' + bucket_id + ' does not exist', 404)
return response('failed', 'No attribute or value was specified, nothing was changed', 400)
return response('failed', 'Content-type must be json', 202)
评论列表
文章目录