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:
@@ -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()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user