Exemplo n.º 1
0
    def process_annotation(
        self,
        insight: ProductInsight,
        data: Optional[Dict] = None,
        auth: Optional[OFFAuthentication] = None,
    ) -> AnnotationResult:
        product = get_product(insight.barcode, ["categories_tags"])

        if product is None:
            return MISSING_PRODUCT_RESULT

        categories_tags: List[str] = product.get("categories_tags") or []

        if insight.value_tag in categories_tags:
            return ALREADY_ANNOTATED_RESULT

        category_tag = insight.value_tag
        add_category(
            insight.barcode,
            category_tag,
            insight_id=insight.id,
            server_domain=insight.server_domain,
            auth=auth,
        )

        return UPDATED_ANNOTATION_RESULT
Exemplo n.º 2
0
    def update_product(self, insight: ProductInsight) -> AnnotationResult:
        product = get_product(insight.barcode, ['categories_tags'])

        if product is None:
            return MISSING_PRODUCT_RESULT

        categories_tags: List[str] = product.get('categories_tags') or []

        if insight.value_tag in categories_tags:
            return ALREADY_ANNOTATED_RESULT

        category_tag = insight.value_tag
        add_category(insight.barcode, category_tag)

        return UPDATED_ANNOTATION_RESULT