Esempio n. 1
0
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))
Esempio n. 2
0
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)
Esempio n. 3
0
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
Esempio n. 4
0
def delete(id_sec):
    InstructionDAOimpl.deleteBySection(id_sec)
    SectionDAOimpl.eraseAllMappingBySection(id_sec)
    SectionDAOimpl.deleteById(id_sec)
Esempio n. 5
0
def read_all():
    instructions = []
    for instruction in InstructionDAOimpl.findAll():
        instructions.append(instruction.to_dict())
    json.dumps(instructions)
    return instructions
Esempio n. 6
0
def delete(id_ins):
    InstructionDAOimpl.deleteById(id_ins)
Esempio n. 7
0
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)
Esempio n. 8
0
def read_by_section(id_section):
    instructions = []
    for instruction in InstructionDAOimpl.findBySection(id_section):
        instructions.append(instruction.to_dict())
    json.dumps(instructions)
    return instructions
Esempio n. 9
0
def read_one(id_ins):
    return InstructionDAOimpl.findOneById(id_ins).to_dict()