Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Price.product_name field #83

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add prices product_name field

Revision ID: 727cb6912bd5
Revises: cce1da5c6733
Create Date: 2023-12-13 13:07:56.309158

"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "727cb6912bd5"
down_revision: Union[str, None] = "cce1da5c6733"
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("prices", sa.Column("product_name", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("prices", "product_name")
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Price(Base):
id = Column(Integer, primary_key=True, index=True)

product_code = Column(String, nullable=True, index=True)
product_name = Column(String, nullable=True)
category_tag = Column(String, nullable=True, index=True)
labels_tags = Column(JSONVariant, nullable=True, index=True)
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), nullable=True)
Expand Down
7 changes: 7 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@ class LocationBase(LocationCreate):

class PriceCreate(BaseModel):
model_config = ConfigDict(from_attributes=True, arbitrary_types_allowed=True)

product_code: str | None = Field(
default=None,
min_length=1,
pattern="^[0-9]+$",
description="barcode (EAN) of the product, as a string.",
examples=["16584958", "8001505005707"],
)
product_name: str | None = Field(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raphael0202 in terms of naming, I hesitated with product_label and product_tag. But there are the existing category_tag & labels_tags so it could be confusing... or maybe product_store_label ? or product_name_in_store ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

product_name sounds good to be!

default=None,
min_length=1,
description="name of the product, as displayed on the receipt or the price tag.",
examples=["PATE NOCCIOLATA BIO 700G"],
)
category_tag: str | None = Field(
default=None,
min_length=3,
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def override_get_db():
LOCATION = LocationCreate(osm_id=3344841823, osm_type="NODE")
PRICE_1 = PriceCreate(
product_code="8001505005707",
product_name="PATE NOCCIOLATA BIO 700G",
# category="en:tomatoes",
price=3.5,
currency="EUR",
Expand Down
Loading