Skip to content

Commit

Permalink
feat: new Product.ecoscore_grade field (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 13, 2024
1 parent ff03b0c commit fa89ef8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add Product ecoscore_grade field
Revision ID: 7055fe5b4775
Revises: d98171064c5a
Create Date: 2024-03-09 12:54:14.104481
"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "7055fe5b4775"
down_revision: Union[str, None] = "d98171064c5a"
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("ecoscore_grade", sa.String(), nullable=True))
# ### end Alembic commands ###


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

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

prices: Mapped[list["Price"]] = relationship(back_populates="product")
Expand Down
6 changes: 5 additions & 1 deletion app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ class ProductFull(ProductCreate):
],
)
nutriscore_grade: str | None = Field(
description="Nutriscore grade.", examples=["a", "unknown"]
description="Nutriscore grade.", examples=["a", "unknown", "not-applicable"]
)
ecoscore_grade: str | None = Field(
description="Ecoscore grade.", examples=["a", "unknown", "not-applicable"]
)
unique_scans_n: int = Field(
description="number of unique scans of the product on Open Food Facts.",
Expand Down Expand Up @@ -456,6 +459,7 @@ class ProductFilter(Filter):
labels_tags__contains: Optional[str] | None = None
brands__like: Optional[str] | None = None
nutriscore_grade: Optional[str] | None = None
ecoscore_grade: Optional[str] | 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 @@ -50,6 +50,7 @@ def init_sentry(
"labels_tags",
"image_url",
"nutriscore_grade",
"ecoscore_grade",
"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 @@ -55,6 +55,7 @@ def override_get_db():
brands_tags=["clement-faugier"],
labels_tags=[],
nutriscore_grade="d",
ecoscore_grade="b",
unique_scans_n=20,
)
PRODUCT_2 = ProductCreate(
Expand All @@ -68,6 +69,7 @@ def override_get_db():
brands_tags=["clement-faugier"],
labels_tags=[],
nutriscore_grade="d",
ecoscore_grade="c",
unique_scans_n=10,
)
PRODUCT_3 = ProductCreate(
Expand All @@ -81,6 +83,7 @@ def override_get_db():
brands_tags=["paysans-d-ici", "ethiquable"],
labels_tags=["en:fair-trade", "en:organic", "en:made-in-france"],
nutriscore_grade="c",
ecoscore_grade="b",
unique_scans_n=0,
)
LOCATION = LocationFull(
Expand Down

0 comments on commit fa89ef8

Please sign in to comment.