Skip to content

Commit

Permalink
feat: new Product.nova_group field (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 14, 2024
1 parent 2527942 commit e611b11
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add Product nova_group field
Revision ID: 295d1735cc72
Revises: 7055fe5b4775
Create Date: 2024-03-14 10:43:59.204833
"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "295d1735cc72"
down_revision: Union[str, None] = "7055fe5b4775"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("products", sa.Column("nova_group", sa.Integer(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("products", "nova_group")
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Product(Base):

nutriscore_grade: Mapped[str | None]
ecoscore_grade: Mapped[str | None]
nova_group: Mapped[int | None]
unique_scans_n = mapped_column(Integer, nullable=False, server_default="0")

prices: Mapped[list["Price"]] = relationship(back_populates="product")
Expand Down
8 changes: 6 additions & 2 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ class ProductFull(ProductCreate):
],
)
nutriscore_grade: str | None = Field(
description="Nutriscore grade.", examples=["a", "unknown", "not-applicable"]
description="Nutri-Score grade.",
examples=["a", "b", "c", "d", "e", "unknown", "not-applicable"],
)
ecoscore_grade: str | None = Field(
description="Ecoscore grade.", examples=["a", "unknown", "not-applicable"]
description="Eco-Score grade.",
examples=["a", "b", "c", "d", "e", "unknown", "not-applicable"],
)
nova_group: int | None = Field(description="NOVA group.", examples=[1, 2, 3, 4])
unique_scans_n: int = Field(
description="number of unique scans of the product on Open Food Facts.",
examples=[15],
Expand Down Expand Up @@ -464,6 +467,7 @@ class ProductFilter(Filter):
brands__like: Optional[str] | None = None
nutriscore_grade: Optional[str] | None = None
ecoscore_grade: Optional[str] | None = None
nova_group: Optional[int] | None = None
unique_scans_n__gte: Optional[int] | None = None
price_count: Optional[int] | None = None
price_count__gte: Optional[int] | None = None
Expand Down
1 change: 1 addition & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def init_sentry(
"image_url",
"nutriscore_grade",
"ecoscore_grade",
"nova_group",
"unique_scans_n",
]

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def override_get_db():
labels_tags=[],
nutriscore_grade="d",
ecoscore_grade="b",
nova_group=4,
unique_scans_n=20,
)
PRODUCT_2 = ProductCreate(
Expand All @@ -70,6 +71,7 @@ def override_get_db():
labels_tags=[],
nutriscore_grade="d",
ecoscore_grade="c",
nova_group=4,
unique_scans_n=10,
)
PRODUCT_3 = ProductCreate(
Expand All @@ -84,6 +86,7 @@ def override_get_db():
labels_tags=["en:fair-trade", "en:organic", "en:made-in-france"],
nutriscore_grade="c",
ecoscore_grade="b",
nova_group=None,
unique_scans_n=0,
)
LOCATION = LocationFull(
Expand Down

0 comments on commit e611b11

Please sign in to comment.