diff --git a/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java b/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java
index 1fab429..b69d74c 100644
--- a/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java
+++ b/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java
@@ -4,6 +4,7 @@ import local.epul4a.fotosharing.model.Photo;
import local.epul4a.fotosharing.model.Utilisateur;
import local.epul4a.fotosharing.repository.PhotoRepository;
import local.epul4a.fotosharing.security.CustomUserDetails;
+import local.epul4a.fotosharing.service.CommentaireService;
import local.epul4a.fotosharing.service.PhotoService;
import org.springframework.core.io.Resource;
import org.springframework.core.io.PathResource;
@@ -25,10 +26,12 @@ public class PhotoController {
private final PhotoService photoService;
private final PhotoRepository photoRepository;
+ private final CommentaireService commentaireService;
- public PhotoController(PhotoService photoService, PhotoRepository photoRepository) {
+ public PhotoController(PhotoService photoService, PhotoRepository photoRepository, CommentaireService commentaireService) {
this.photoService = photoService;
this.photoRepository = photoRepository;
+ this.commentaireService = commentaireService;
}
@GetMapping("/upload")
@@ -91,6 +94,37 @@ public class PhotoController {
return "galerie";
}
+ @GetMapping("/photo/{id}")
+ public String viewPhoto(@PathVariable Long id,
+ Model model,
+ Authentication auth) {
+
+ Photo photo = photoRepository.findById(id).orElse(null);
+ if (photo == null) {
+ return "redirect:/galerie";
+ }
+
+ model.addAttribute("photo", photo);
+ model.addAttribute("commentaires", commentaireService.listByPhoto(id));
+
+ // utilisateur connecté (peut être null si visiteur)
+ String currentUser = (auth != null ? auth.getName() : null);
+ model.addAttribute("currentUser", currentUser);
+
+ return "photo-detail";
+ }
+
+ @PostMapping("/photo/{id}/comment")
+ public String addComment(@PathVariable Long id,
+ @RequestParam String contenu,
+ Authentication auth) {
+ if (auth == null) {
+ return "redirect:/login";
+ }
+ String email = auth.getName();
+ commentaireService.addComment(id, email, contenu);
+ return "redirect:/photo/" + id;
+ }
}
diff --git a/src/main/java/local/epul4a/fotosharing/repository/CommentaireRepository.java b/src/main/java/local/epul4a/fotosharing/repository/CommentaireRepository.java
new file mode 100644
index 0000000..bd75032
--- /dev/null
+++ b/src/main/java/local/epul4a/fotosharing/repository/CommentaireRepository.java
@@ -0,0 +1,11 @@
+package local.epul4a.fotosharing.repository;
+
+import local.epul4a.fotosharing.model.Commentaire;
+import org.springframework.data.jpa.repository.JpaRepository;
+import java.util.List;
+
+public interface CommentaireRepository extends JpaRepository
+ Accueil | + Galerie publique | + Mes photos +
+ + +Aucun commentaire pour l'instant.
+Connectez-vous pour commenter.
+diff --git a/src/main/resources/templates/mes-photos.html b/src/main/resources/templates/mes-photos.html index ebaac9a..860c13c 100644 --- a/src/main/resources/templates/mes-photos.html +++ b/src/main/resources/templates/mes-photos.html @@ -18,7 +18,7 @@
diff --git a/src/main/resources/templates/photo-detail.html b/src/main/resources/templates/photo-detail.html new file mode 100644 index 0000000..cf951ff --- /dev/null +++ b/src/main/resources/templates/photo-detail.html @@ -0,0 +1,62 @@ + + +
+ +
+ +
+