redesing product lists

This commit is contained in:
2025-05-28 11:01:42 +02:00
parent 330124837f
commit eb3ae05425
12 changed files with 1569 additions and 809 deletions

View File

@@ -30,7 +30,7 @@ def build_shopping_event_response(event: models.ShoppingEvent, db: Session) -> s
product_data = db.execute(
text("""
SELECT p.id, p.name, p.organic, p.weight, p.weight_unit,
sep.amount, sep.price,
sep.amount, sep.price, sep.discount,
gc.id as category_id, gc.name as category_name,
gc.created_at as category_created_at, gc.updated_at as category_updated_at,
b.id as brand_id, b.name as brand_name,
@@ -73,7 +73,8 @@ def build_shopping_event_response(event: models.ShoppingEvent, db: Session) -> s
weight=row.weight,
weight_unit=row.weight_unit,
amount=row.amount,
price=row.price
price=row.price,
discount=row.discount
)
)
@@ -413,7 +414,8 @@ def create_shopping_event(event: schemas.ShoppingEventCreate, db: Session = Depe
shopping_event_id=db_event.id,
product_id=product_item.product_id,
amount=product_item.amount,
price=product_item.price
price=product_item.price,
discount=product_item.discount
)
)
@@ -470,7 +472,8 @@ def update_shopping_event(event_id: int, event_update: schemas.ShoppingEventCrea
shopping_event_id=event_id,
product_id=product_item.product_id,
amount=product_item.amount,
price=product_item.price
price=product_item.price,
discount=product_item.discount
)
)

View File

@@ -14,7 +14,8 @@ shopping_event_products = Table(
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), nullable=False),
Column('product_id', Integer, ForeignKey('products.id'), nullable=False),
Column('amount', Float, nullable=False), # Amount of this product bought in this event
Column('price', Float, nullable=False) # Price of this product at the time of this shopping event
Column('price', Float, nullable=False), # Price of this product at the time of this shopping event
Column('discount', Boolean, default=False, nullable=False) # Whether this product was purchased with a discount
)
# Association table for many-to-many self-referential relationship between related products

View File

@@ -117,6 +117,7 @@ class ProductInEvent(BaseModel):
product_id: int
amount: float = Field(..., gt=0)
price: float = Field(..., ge=0) # Price at the time of this shopping event (allow free items)
discount: bool = False # Whether this product was purchased with a discount
class ProductWithEventData(BaseModel):
id: int
@@ -128,6 +129,7 @@ class ProductWithEventData(BaseModel):
weight_unit: str
amount: float # Amount purchased in this event
price: float # Price at the time of this event
discount: bool # Whether this product was purchased with a discount
class Config:
from_attributes = True