def compare_product()

in products/src/validate/main.py [0:0]


def compare_product(user_product: dict, ddb_product: Optional[dict]) -> Optional[Set[Union[dict, str]]]:
    """
    Compare the user-provided product with the data provided by DynamoDB
    """

    if ddb_product is None:
        return user_product, "Product '{}' not found".format(user_product["productId"])

    # Validate schema
    for key in ddb_product.keys():
        if key not in user_product:
            return ddb_product, "Missing '{}' in product '{}'".format(key, user_product["productId"])

        if user_product[key] != ddb_product[key]:
            return ddb_product, "Invalid value for '{}': want '{}', got '{}' in product '{}'".format(
                key, ddb_product[key], user_product[key], user_product["productId"]
            )

    # All good, return nothing
    return None