def add_section(id_recipe, section): section_to_insert = Section(None, section.get("name", None), id_recipe) id_section = SectionDAOimpl.insert(section_to_insert) for ingredient in section.get("ingredients", None): SectionDAOimpl.addIngredientToDB(id_section, ingredient.get("id_ingredient", None), ingredient.get("quantity", None), ingredient.get("unit", None)) for instruction in section.get("instructions", None): InstructionDAOimpl.insert(Instruction(None, instruction.get("text", None), id_section))
def delete_full(id_recipe): for section in SectionDAOimpl.findByRecipe(id_recipe): InstructionDAOimpl.deleteBySection(section.id_sec) SectionDAOimpl.eraseAllMappingBySection(section.id_sec) SectionDAOimpl.deleteById(section.id_sec) for image in ImageDAOImpl.findByRecipe(id_recipe): ImageDAOImpl.deleteById(image.id_img) RecipeDAOimpl.eraseCategoryMapping(id_recipe) RecipeDAOimpl.eraseToolMapping(id_recipe) RecipeDAOimpl.deleteById(id_recipe)
def create(instruction): text = instruction.get("text", None) id_section = instruction.get("id_section", None) instruction = Instruction(None, text, id_section) id_instruction = InstructionDAOimpl.insert(instruction) json.dumps(id_instruction) return id_instruction
def delete(id_sec): InstructionDAOimpl.deleteBySection(id_sec) SectionDAOimpl.eraseAllMappingBySection(id_sec) SectionDAOimpl.deleteById(id_sec)
def read_all(): instructions = [] for instruction in InstructionDAOimpl.findAll(): instructions.append(instruction.to_dict()) json.dumps(instructions) return instructions
def delete(id_ins): InstructionDAOimpl.deleteById(id_ins)
def update(id_ins, instruction): text = instruction.get("text", None) id_section = instruction.get("id_section", None) instruction = Instruction(id_ins, text, id_section) InstructionDAOimpl.update(instruction)
def read_by_section(id_section): instructions = [] for instruction in InstructionDAOimpl.findBySection(id_section): instructions.append(instruction.to_dict()) json.dumps(instructions) return instructions
def read_one(id_ins): return InstructionDAOimpl.findOneById(id_ins).to_dict()