add price request after adding
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package fr.tetelie.crawler.web;
|
||||
package fr.tetelie.crawler.web; // Vérifie bien ton nom de package
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -14,6 +13,7 @@ public class PriceHistory {
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
// Attention : le nom ici doit être identique à ta colonne SQL
|
||||
@Column(name = "checked_at")
|
||||
private LocalDateTime dateCheck;
|
||||
|
||||
@ -21,7 +21,24 @@ public class PriceHistory {
|
||||
@JoinColumn(name = "product_id")
|
||||
private Product product;
|
||||
|
||||
// Getters & Setters
|
||||
// --- GETTERS (Pour lire les données) ---
|
||||
public Integer getId() { return id; }
|
||||
public BigDecimal getPrice() { return price; }
|
||||
public LocalDateTime getDateCheck() { return dateCheck; }
|
||||
public Product getProduct() { return product; }
|
||||
|
||||
// --- SETTERS (Indispensables pour enregistrer les données) ---
|
||||
public void setId(Integer id) { this.id = id; }
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setDateCheck(LocalDateTime dateCheck) {
|
||||
this.dateCheck = dateCheck;
|
||||
}
|
||||
|
||||
public void setProduct(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
}
|
||||
@ -36,8 +36,25 @@ public class ProductController {
|
||||
System.out.println("Aucune image trouvée pour ce lien.");
|
||||
}
|
||||
|
||||
|
||||
DatabaseConfig.getInstance().updatesAllMissingImages();
|
||||
productRepository.save(p);
|
||||
|
||||
Product savedProduct = productRepository.save(p);
|
||||
|
||||
float currentPrice = WebScrapper.getInstance().requestPrice(link);
|
||||
|
||||
if (currentPrice > 0) {
|
||||
// 4. On crée la première entrée dans l'historique
|
||||
PriceHistory firstPrice = new PriceHistory();
|
||||
firstPrice.setProduct(savedProduct);
|
||||
// On convertit le float en BigDecimal pour coller à ta base
|
||||
firstPrice.setPrice(java.math.BigDecimal.valueOf(currentPrice));
|
||||
firstPrice.setDateCheck(java.time.LocalDateTime.now());
|
||||
|
||||
priceHistoryRepository.save(firstPrice);
|
||||
System.out.println("✅ Produit ajouté avec image et premier prix (" + currentPrice + "€)");
|
||||
}
|
||||
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user