mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-18 20:58:59 +02:00
corretion
This commit is contained in:
1 parent
1893988bb1
commit
f7059da02a
5 files changed
+73
-42
No files matched your search
+22
-3
@@ -39,7 +39,7 @@ def update_item_category(item_id: int, category: str | None = None, db: Session
|
||||
item = db.query(models.Item).filter(models.Item.id == item_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
|
||||
|
||||
# Treat empty string as None
|
||||
item.category = category if category and category.strip() else None
|
||||
db.commit()
|
||||
@@ -77,7 +77,7 @@ def get_price_history(item_id: int, db: Session = Depends(database.get_db)):
|
||||
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)
|
||||
@@ -85,5 +85,24 @@ def get_price_history(item_id: int, db: Session = Depends(database.get_db)):
|
||||
.order_by(models.PriceHistory.timestamp.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
return price_history
|
||||
|
||||
|
||||
@router.patch("/{item_id}/availability")
|
||||
def update_item_availability(item_id: int, available: bool = True, db: Session = Depends(database.get_db)):
|
||||
"""Mark an item as available or unavailable manually"""
|
||||
item = db.query(models.Item).filter(models.Item.id == item_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
|
||||
item.is_available = available
|
||||
# Also clear the error if marking as available
|
||||
if available and item.last_error and "indisponible" in item.last_error.lower():
|
||||
item.last_error = None
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return {
|
||||
"message": f"Item marked as {'available' if available else 'unavailable'}",
|
||||
"is_available": item.is_available,
|
||||
}
|
||||
@@ -57,6 +57,12 @@ def _update_db_result(
|
||||
item.current_price = price
|
||||
item.current_price_confidence = p_conf
|
||||
|
||||
# Auto-reset availability if price was successfully extracted
|
||||
# A valid price proves the product is still available
|
||||
if item.is_available is False:
|
||||
item.is_available = True
|
||||
logger.info(f"Item {item_id} marked as available again (price found: {price})")
|
||||
|
||||
session.add(
|
||||
models.PriceHistory(
|
||||
item_id=item.id,
|
||||
|
||||
Reference in new issue
Block a user