Ejemplo 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))
Ejemplo 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)
Ejemplo n.º 3
0
def create(section):
    name = section.get("name", None)
    id_recipe = section.get("id_recipe", None)
    section = Section(None, name, id_recipe)
    id_section = SectionDAOimpl.insert(section)
    json.dumps(id_section)
    return id_section
Ejemplo n.º 4
0
def read_all():
    sections = []
    for section in SectionDAOimpl.findAll():
        sections.append(section.to_dict())
    json.dumps(sections)
    return sections
Ejemplo n.º 5
0
def delete_mapping(id_sec, id_ing):
    SectionDAOimpl.removeIngredientFromDB(id_sec, id_ing)
Ejemplo n.º 6
0
def set_ingredient(id_sec, id_ing, properties):
    quantity = properties.get("quantity", None)
    unit = properties.get("unit", None)
    SectionDAOimpl.addIngredientToDB(id_sec, id_ing, quantity, unit)
Ejemplo n.º 7
0
def delete(id_sec):
    InstructionDAOimpl.deleteBySection(id_sec)
    SectionDAOimpl.eraseAllMappingBySection(id_sec)
    SectionDAOimpl.deleteById(id_sec)
Ejemplo n.º 8
0
def update(id_sec, section):
    name = section.get("name", None)
    id_recipe = section.get("id_recipe", None)
    section = Section(id_sec, name, id_recipe)
    SectionDAOimpl.update(section)
Ejemplo n.º 9
0
def read_one(id_sec):
    return SectionDAOimpl.findOneById(id_sec).to_dict()
Ejemplo n.º 10
0
def read_by_recipe(id_recipe):
    sections = []
    for section in SectionDAOimpl.findByRecipe(id_recipe):
        sections.append(section.to_dict())
    json.dumps(sections)
    return sections