Skip to content

Commit

Permalink
feat: add Price.product_name field (#83)
Browse files Browse the repository at this point in the history
* Add price.product_name field

* Remove index. Fix typo
  • Loading branch information
raphodn authored Dec 14, 2023
1 parent ed34567 commit 36d551f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
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(
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

0 comments on commit 36d551f

Please sign in to comment.