diff --git a/pom.xml b/pom.xml index de8577b..ab3f930 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,25 @@ UTF-8 + + org.springframework.boot + spring-boot-starter-parent + 3.2.2 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-data-jpa + org.jsoup jsoup diff --git a/src/main/java/fr/tetelie/crawler/Crawler.java b/src/main/java/fr/tetelie/crawler/Crawler.java index 8cabf84..882a751 100644 --- a/src/main/java/fr/tetelie/crawler/Crawler.java +++ b/src/main/java/fr/tetelie/crawler/Crawler.java @@ -3,7 +3,12 @@ package fr.tetelie.crawler; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; +@SpringBootApplication +@EnableScheduling public class Crawler { @@ -19,6 +24,8 @@ public class Crawler { // Si pas de connexion à la base de donnée on s'arrête ici if(!isConnected){return;}; + SpringApplication.run(Crawler.class, args); + // On request les prix de tous les produits et on les inject dans la bdd diff --git a/src/main/java/fr/tetelie/crawler/web/Product.java b/src/main/java/fr/tetelie/crawler/web/Product.java new file mode 100644 index 0000000..e5f4a91 --- /dev/null +++ b/src/main/java/fr/tetelie/crawler/web/Product.java @@ -0,0 +1,30 @@ +package fr.tetelie.crawler.web; + +import jakarta.persistence.*; + +@Entity +@Table(name = "products") // Correspond au nom de ta table SQL +public class Product { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + @Column(name = "link") // Le nom exact de ta colonne SQL + private String link; + + @Column(name = "image_url") + private String imageUrl; + + // Getters et Setters (indispensables pour Spring) + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + public String getName() { return name; } + public void setName(String name) { this.name = name; } + public String getLink() { return link; } + public void setLink(String link) { this.link = link; } + public String getImageUrl() { return imageUrl; } + public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } +} \ No newline at end of file diff --git a/src/main/java/fr/tetelie/crawler/web/ProductController.java b/src/main/java/fr/tetelie/crawler/web/ProductController.java new file mode 100644 index 0000000..03d6914 --- /dev/null +++ b/src/main/java/fr/tetelie/crawler/web/ProductController.java @@ -0,0 +1,35 @@ +package fr.tetelie.crawler.web; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class ProductController { + + @Autowired + private ProductRepository productRepository; // Spring gère SQL tout seul ! + + @GetMapping("/") + public String listProducts(Model model) { + model.addAttribute("products", productRepository.findAll()); + return "index"; // Ça va chercher src/main/resources/templates/index.html + } + + @PostMapping("/add") + public String addProduct(@RequestParam String link) { + Product p = new Product(); + p.setLink(link); + productRepository.save(p); + return "redirect:/"; + } + + @GetMapping("/delete/{id}") + public String deleteProduct(@PathVariable Long id) { + productRepository.deleteById(id); + return "redirect:/"; + } +} \ No newline at end of file diff --git a/src/main/java/fr/tetelie/crawler/web/ProductRepository.java b/src/main/java/fr/tetelie/crawler/web/ProductRepository.java new file mode 100644 index 0000000..fdb7650 --- /dev/null +++ b/src/main/java/fr/tetelie/crawler/web/ProductRepository.java @@ -0,0 +1,9 @@ +package fr.tetelie.crawler.web; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepository extends JpaRepository { + // Tu as maintenant accès à : save(), findAll(), deleteById(), etc. +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..7299104 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_USER} +spring.datasource.password=${DB_PASS} +spring.jpa.hibernate.ddl-auto=update +server.port=8083 \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..d0041c0 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,32 @@ + + + + Iceberg Price Tracker + + + + +

🧊 Iceberg Dashboard

+ +
+ + +
+ +
+
+
+ +

Nom du produit

+ 🗑️ +
+ + + + +
+
+ + \ No newline at end of file