Пример #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))
Пример #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)
Пример #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
Пример #4
0
def delete(id_sec):
    InstructionDAOimpl.deleteBySection(id_sec)
    SectionDAOimpl.eraseAllMappingBySection(id_sec)
    SectionDAOimpl.deleteById(id_sec)
Пример #5
0
def read_all():
    instructions = []
    for instruction in InstructionDAOimpl.findAll():
        instructions.append(instruction.to_dict())
    json.dumps(instructions)
    return instructions
Пример #6
0
def delete(id_ins):
    InstructionDAOimpl.deleteById(id_ins)
Пример #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)
Пример #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
Пример #9
0
def read_one(id_ins):
    return InstructionDAOimpl.findOneById(id_ins).to_dict()