FEAT : Ajout pagination galerie publique

This commit is contained in:
2025-12-02 09:12:07 +01:00
parent 109cc8065e
commit 6cb141293c
15 changed files with 181 additions and 78 deletions

View File

@@ -11,6 +11,7 @@ import local.epul4a.fotosharing.service.CommentaireService;
import local.epul4a.fotosharing.service.PhotoService;
import org.springframework.core.io.Resource;
import org.springframework.core.io.PathResource;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -91,24 +92,23 @@ public class PhotoController {
}
@GetMapping("/mes-photos")
public String mesPhotos(Model model, Authentication authentication) {
String email = authentication.getName();
// photos que je possède
List<Photo> mesPhotos = photoService.listByOwner(email);
// photos partagées avec moi
List<Photo> photosPartagees = photoService.listSharedWith(email);
model.addAttribute("mesPhotos", mesPhotos);
model.addAttribute("photosPartagees", photosPartagees);
public String mesPhotos(Model model, Authentication auth) {
String email = auth.getName();
model.addAttribute("photosPrivees", photoService.listPrivatePhotos(email));
model.addAttribute("photosPubliques", photoService.listPublicPhotos(email));
model.addAttribute("photosPartagees", photoService.listSharedWith(email));
return "mes-photos";
}
@GetMapping("/galerie")
public String galerie(Model model) {
model.addAttribute("photos", photoService.listPublicPhotos());
public String galerie(@RequestParam(defaultValue = "0") int page, Model model) {
Page<Photo> photosPage = photoService.listPublic(page, 12);
model.addAttribute("photosPage", photosPage);
model.addAttribute("currentPage", page);
return "galerie";
}
@GetMapping("/photo/{id}")
@PreAuthorize("@securityService.canAccessPhoto(authentication, #id)")
public String viewPhoto(@PathVariable Long id,
@@ -127,6 +127,10 @@ public class PhotoController {
String currentUser = (auth != null ? auth.getName() : null);
model.addAttribute("currentUser", currentUser);
// Liste des partages
List<Partage> partages = partageRepository.findByPhoto_Id(id);
model.addAttribute("partages", partages);
return "photo-detail";
}
@@ -166,6 +170,12 @@ public class PhotoController {
return "redirect:/photo/" + id + "?shared=ok";
}
@GetMapping("/photo/{id}/unshare/{email}")
public String unshare(@PathVariable Long id, @PathVariable String email) {
photoService.unshare(id, email);
return "redirect:/photo/" + id;
}
}