feat: auto-scrape on product creation and update product data (Step 4)

- Add automatic scraping when creating a new product
- Update product title and image from scraped data
- Add GET /products/{id}/snapshots endpoint for price history
- Add list_snapshots and get_latest_snapshot to CRUD

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-18 19:33:04 +01:00
parent 744d16c2c5
commit 4ff5d3ee79
3 changed files with 59 additions and 4 deletions

View File

@@ -43,3 +43,22 @@ def update_product(db: Session, product: models.Product, changes: schemas.Produc
def remove_product(db: Session, product: models.Product) -> None:
db.delete(product)
db.commit()
def list_snapshots(db: Session, product_id: int, limit: int = 30) -> list[models.ProductSnapshot]:
return (
db.query(models.ProductSnapshot)
.filter(models.ProductSnapshot.produit_id == product_id)
.order_by(models.ProductSnapshot.scrape_le.desc())
.limit(limit)
.all()
)
def get_latest_snapshot(db: Session, product_id: int) -> models.ProductSnapshot | None:
return (
db.query(models.ProductSnapshot)
.filter(models.ProductSnapshot.produit_id == product_id)
.order_by(models.ProductSnapshot.scrape_le.desc())
.first()
)