def handle_books_id(place_id, book_id):
'''Returns a JSON object of the book_id with a GET request method. Updates
a booking's attributes with a POST request method. Removes a booking with a
DELETE request method.
Keyword arguments:
place_id: The id of the place with the booking.
book_id: The id of the booking.
'''
try:
book = PlaceBook.select().where(PlaceBook.id == book_id).get()
except PlaceBook.DoesNotExist:
raise Exception("There is no placebook with this id.")
if request.method == 'GET':
return jsonify(book.to_dict()), 200
elif request.method == 'PUT':
params = request.values
for key in params:
if key == 'user':
return jsonify(msg="You may not change the user."), 409
if key == 'updated_at' or key == 'created_at':
continue
setattr(book, key, params.get(key))
book.save()
return jsonify(msg="Place book information updated successfully."), 200
elif request.method == 'DELETE':
try:
book = PlaceBook.delete().where(PlaceBook.id == book_id)
except PlaceBook.DoesNotExist:
raise Exception("There is no place with this id.")
book.execute()
return jsonify(msg="Place book deleted successfully."), 200
评论列表
文章目录