Esempio n. 1
0
    def create(brand_id, food_id, bar_code, chemicals):

        if not chemicals or len(chemicals) == 0:
            return {"message": "Quimicos não informados"}, 400

        if not barcodenumber.check_code_ean13(bar_code):
            return {"message": "Codigo de barras invalido"}, 412

        relation = BrandFoodModel.find_by_bar_code(bar_code)
        if relation:
            return {"message": "Codigo de barras já cadastrado"}, 409

        relation = BrandFoodModel(brand_id, food_id, bar_code)
        try:
            relation.save()

            for chemical in chemicals:
                BrandFoodChemicalService.create(brand_id, food_id, chemical)

            db.session.commit()

        except IntegrityError:
            db.session.rollback()
            return {"message": "Item já cadastrado"}, 409
        except Exception as e:
            db.session.rollback()
            logger.error(e, exc_info=True)
            return {"message": "Error ao salvar relacionamento"}, 500
        return relation.json(), 201
Esempio n. 2
0
    def get_chemicals_by_barcode(bar_code):
        if not barcodenumber.check_code_ean13(bar_code):
            return {"message": "Codigo de barras invalido"}, 412

        relation = BrandFoodModel.find_by_bar_code(bar_code)
        if not relation:
            return {"message": "Codigo de barra não encontrado"}, 404

        return BrandFoodService.get_chemicals(relation.id_brand, relation.id_food)
Esempio n. 3
0
    def get_foods_brand_by_barcode(bar_code):
        if not barcodenumber.check_code_ean13(bar_code):
            return {"message": "Codigo de barras invalido"}, 412

        relation = BrandFoodModel.find_by_bar_code(bar_code)
        if not relation:
            return {"message": "Codigo de barra não encontrado"}, 404

        return relation.json();