From 3ae3e84e37b06a52c51dc761819a6210536ee4c1 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 23 Nov 2025 22:27:09 +0100 Subject: [PATCH] feat: Introduce item API endpoints for CRUD, category management, price checks, and their Pydantic schemas. --- app/routers/items.py | 18 ++++++++++++++++++ app/schemas.py | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/app/routers/items.py b/app/routers/items.py index 7fb5e34..6e88802 100644 --- a/app/routers/items.py +++ b/app/routers/items.py @@ -69,3 +69,21 @@ def check_item( background_tasks.add_task(process_item_check, item_id) return {"message": "Check triggered"} + + +@router.get("/{item_id}/price-history", response_model=list[schemas.PriceHistoryResponse]) +def get_price_history(item_id: int, db: Session = Depends(database.get_db)): + """Get price history for a specific item""" + item = db.query(models.Item).filter(models.Item.id == item_id).first() + if not item: + raise HTTPException(status_code=404, detail="Item not found") + + # Get price history sorted by timestamp descending (most recent first) + price_history = ( + db.query(models.PriceHistory) + .filter(models.PriceHistory.item_id == item_id) + .order_by(models.PriceHistory.timestamp.desc()) + .all() + ) + + return price_history diff --git a/app/schemas.py b/app/schemas.py index 228bced..9cb2d03 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -47,6 +47,15 @@ class ItemResponse(ItemCreate): model_config = ConfigDict(from_attributes=True) +class PriceHistoryResponse(BaseModel): + id: int + price: float + timestamp: datetime + price_confidence: float | None = None + in_stock_confidence: float | None = None + model_config = ConfigDict(from_attributes=True) + + class SettingsUpdate(BaseModel): key: str value: str