def put_ingredient(_id): """ update one ingredient """ put_ingredient_validator.is_object_id(_id) body = put_ingredient_factory.clean_body(request.json) put_ingredient_validator.is_body_valid(body) put_ingredient_validator.is_name_already_exist(body) updated = ingredient.update(_id, body) return factory.ServerResponse().format_response(data=updated, api="ingredient", is_mongo=True, code=200)
def post_ingredient(): """ insert one ingredient """ """ name is mandatory """ body = post_ingredient_factory.clean_body(request.json) post_ingredient_validator.is_body_valid(body) post_ingredient_validator.is_name_already_exist(body) inserted = ingredient.insert(body) return factory.ServerResponse().format_response(data=inserted, api="ingredient", is_mongo=True, code=201)
def put_recipe(_id): """ update one recipe """ put_recipe_validator.is_object_id(_id) body = put_recipe_factory.clean_body(request.json) put_recipe_validator.is_body_valid(body) put_recipe_validator.is_title_already_exist(body) updated = recipe.update(_id, body) return factory.ServerResponse().format_response(data=updated, api="recipe", is_mongo=True, code=200)
def not_found(error): """" abort 404 """ return factory.ServerResponse().format_response(data=error.description, api="recipe_steps", is_mongo=False, code=404)
def validator_failed(error): """" abort 400 """ return factory.ServerResponse().format_response(data=error.description, api="recipe_steps", is_mongo=False, code=400)
def delete_recipe_step(_id, _index): """ delete one step to a recipe """ delete_recipe_step_validator.is_object_id(_id) delete_recipe_step_validator.is_index_valid(_id, _index) deleted = steps.delete(_id, _index) return factory.ServerResponse().format_response(data=None, api="recipe", is_mongo=True, code=204)
def method_not_allowed(error): """" abort 405 """ body = factory.ServerResponse().format_response(data=error.description, api="cookbook", is_mongo=False, code=405) return make_response(body, 405)
def not_found(error): """" abort 404 """ body = factory.ServerResponse().format_response(data=error.description, api="cookbook", is_mongo=False, code=404) return make_response(body, 404)