def update_image(): if get_jwt_header()['type'] == "Chef": chef = Chef.get_or_none(Chef.email == get_jwt_identity()) if request.content_length == 0: return jsonify(message="No images passed", status="failed"), 400 elif request.files['chef_image']: file = request.files.get('chef_image') s3.upload_fileobj( file, "foodapp-new", f"chefs/{chef.id}/{file.filename}", ExtraArgs={ "ACL": "public-read", "ContentType": file.content_type } ) update = Chef.update({Chef.image_path:f"https://foodapp-new.s3-ap-southeast-1.amazonaws.com/chefs/{chef.id}/{file.filename}"}).where(Chef.username == chef.username).execute() updated_chef = Chef.get(Chef.id == chef.id) return jsonify({ "message": "Successfully updated chefs's profile image", "user_id": updated_chef.id, "image": updated_chef.image_path, }), 200 else: return jsonify(message="You are not logged in as Chef"), 400
def update(): current_chef = get_jwt_identity() chef = Chef.get_or_none(Chef.email==current_chef) if get_jwt_header()['type'] == 'Chef': params = request.get_json() if params: params.update({'updated_at': datetime.datetime.now()}) for each in params: update = Chef.update(params).where(Chef.id == chef.id) if update.execute(): return jsonify({ "message": "Successfully updated", "menu_id": chef.id, "updated_at": chef.updated_at, "updated_column": [each for each in params] }) elif params == None: return jsonify({ "message": "No fields are passed", "status": "failed" }), 400 else: return jsonify(message="You are logged in as user instead of chef", status= "failed"), 400