def chef_approve(booking_id): if get_jwt_header()['type'] == "Chef": current_chef = Chef.get_or_none(Chef.email == get_jwt_identity()) booking = Booking.get_or_none(Booking.id == booking_id) if booking: if booking.chef_id == current_chef.id: booking.confirmed = True if booking.save(): return jsonify({ "booking_id": booking_id, "completed": booking.completed, "payment_status": booking.payment_status, "confirmed": booking.confirmed, "active": booking.active, "cancelled": booking.cancelled, "status": "success" }), 200 else: return jsonify({ "message": "You are logged in as another chef", "booking_chef_id": booking.chef_id, "status": "failed" }), 400 else: return jsonify({ "message": "Booking does not exist", "status": "Failed" }), 400 else: return jsonify({ "message": "You have to log in as Chef, not user", "status": "Failed" }), 400
def booking_id(booking_id): booking = Booking.get_or_none(Booking.id == booking_id) if booking: return jsonify({ "booking_id": booking.id, "user": booking.user_id, "chef": booking.chef_id, "address": booking.address, "service_type": booking.service_type, "pax": booking.pax, "meal_type": booking.meal_type, "menu_type": booking.menu_type, "hob_type": booking.hob_type, "no_of_hob": booking.no_of_hob, "oven": booking.oven, "price": booking.price, "diet_restrictions": booking.diet_restrictions, "proposed_date": booking.proposed_date, "message": booking.message, "completed": booking.completed, "payment_status": booking.payment_status, "confirmed": booking.confirmed, "active": booking.active, "cancelled": booking.cancelled }), 200 else: return jsonify({ "message": "This booking does not exist", "status": "Failed" }), 400
def delete(booking_id): booking = Booking.get_or_none(Booking.id == booking_id) if booking: if booking.delete_instance(): return jsonify({"message": "Successfully deleted", "booking_id": booking_id, "status": "success"}), 200 else: return jsonify({"message": "Unable to delete", "status": "failed"}), 400 else: return jsonify({"message": "Unable to find this booking", "status": "failed"}), 400
def user_cancel(booking_id): if get_jwt_header()['type'] == "User": current_user = User.get_or_none(User.email == get_jwt_identity()) booking = Booking.get_or_none(Booking.id == booking_id) if booking: if booking.user_id == current_user.id: booking.active = False booking.cancelled = True if booking.save(): return jsonify({ "booking_id": booking_id, "completed": booking.completed, "payment_status": booking.payment_status, "confirmed": booking.confirmed, "active": booking.active, "cancelled": booking.cancelled, "status": "success" }), 200 else: return jsonify({ "message": "Unable to cancel booking", "status": "Failed" }), 400 else: return jsonify({ "message": "You are logged in as another user", "booking_chef_id": booking.chef_id, "status": "failed" }), 400 else: return jsonify({ "message": "Booking does not exist", "status": "Failed" }), 400 else: return jsonify({ "message": "You have to log in as User, not Chef", "status": "Failed" }), 400
def update(booking_id): booking = Booking.get_or_none(Booking.id==booking_id) params = request.get_json() current_user = get_jwt_identity() if get_jwt_header()['type'] != "User": return jsonify(message="You are logged in as Chef, not user. Only user can edit booking.", status="success"), 400 else: if booking and params: params.update({'updated_at': datetime.datetime.now()}) for each in params: update = Booking.update(params).where(Booking.id == booking_id) if update.execute(): return jsonify({ "message": "Successfully updated", "booking_id": booking.id, "updated_at": booking.updated_at, "updated_column": [each for each in params], "completed": booking.completed, "payment_status": booking.payment_status, "confirmed": booking.confirmed, "active": booking.active, "cancelled": booking.cancelled }) else: return jsonify({ "message": "Unable to update, please try again", "status": "failed" }), 400 elif booking == None: return jsonify({ "message": "This booking doesn't exist", "status": "failed" }),400 elif params == None: return jsonify({ "message": "No fields are passed", "status": "failed" }), 400