FEAT : ajout compteur de partage

This commit is contained in:
2025-12-03 09:28:16 +01:00
parent b144a44a0a
commit 66045aaf14
10 changed files with 48 additions and 26 deletions

View File

@@ -20,6 +20,8 @@ import org.springframework.web.multipart.MultipartFile;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@Controller @Controller
public class PhotoController { public class PhotoController {
@@ -84,7 +86,6 @@ public class PhotoController {
/* ========================== MES PHOTOS ========================== */ /* ========================== MES PHOTOS ========================== */
@GetMapping("/mes-photos") @GetMapping("/mes-photos")
public String mesPhotos( public String mesPhotos(
@RequestParam(defaultValue = "0") int pagePrivees, @RequestParam(defaultValue = "0") int pagePrivees,
@@ -92,30 +93,32 @@ public class PhotoController {
@RequestParam(defaultValue = "0") int pagePartagees, @RequestParam(defaultValue = "0") int pagePartagees,
@RequestParam(defaultValue = "0") int pageMesPartagees, @RequestParam(defaultValue = "0") int pageMesPartagees,
Authentication auth, Model model) { Authentication auth, Model model) {
String email = auth.getName(); String email = auth.getName();
// Récupération des pages
model.addAttribute("photosPrivees", Page<PhotoDTO> photosPrivees = photoService.listPrivatePhotos(email, pagePrivees, 12);
photoService.listPrivatePhotos(email, pagePrivees, 12)); Page<PhotoDTO> photosPubliques = photoService.listPublicPhotos(email, pagePubliques, 12);
Page<PhotoDTO> photosPartagees = photoService.listSharedWith(email, pagePartagees, 12);
model.addAttribute("photosPubliques", Page<PhotoDTO> mesPhotosPartagees = photoService.listSharedPhotos(email, pageMesPartagees, 12);
photoService.listPublicPhotos(email, pagePubliques, 12)); // Calcul du nombre de partages pour TOUTES mes photos SHARED
Map<Long, Integer> shareCounts = new HashMap<>();
model.addAttribute("photosPartagees", mesPhotosPartagees.getContent().forEach(p -> {
photoService.listSharedWith(email, pagePartagees, 12)); shareCounts.put(p.getId(), partageService.countShares(p.getId()));
});
model.addAttribute("mesPhotosPartagees", // Envoi au model
photoService.listSharedPhotos(email, pageMesPartagees, 12)); model.addAttribute("photosPrivees", photosPrivees);
model.addAttribute("photosPubliques", photosPubliques);
model.addAttribute("photosPartagees", photosPartagees);
model.addAttribute("mesPhotosPartagees", mesPhotosPartagees);
model.addAttribute("shareCounts", shareCounts);
model.addAttribute("pagePrivees", pagePrivees); model.addAttribute("pagePrivees", pagePrivees);
model.addAttribute("pagePubliques", pagePubliques); model.addAttribute("pagePubliques", pagePubliques);
model.addAttribute("pagePartagees", pagePartagees); model.addAttribute("pagePartagees", pagePartagees);
model.addAttribute("pageMesPartagees", pageMesPartagees); model.addAttribute("pageMesPartagees", pageMesPartagees);
return "mes-photos"; return "mes-photos";
} }
/* ========================== GALERIE ========================== */ /* ========================== GALERIE ========================== */
@GetMapping("/galerie") @GetMapping("/galerie")

View File

@@ -12,4 +12,5 @@ public interface PartageRepository extends JpaRepository<Partage, Long> {
boolean existsByPhoto_IdAndUtilisateur_Email(Long photoId, String email); boolean existsByPhoto_IdAndUtilisateur_Email(Long photoId, String email);
List<Partage> findByUtilisateur_Email(String email); List<Partage> findByUtilisateur_Email(String email);
Optional<Partage> findByPhoto_IdAndUtilisateur_Email(Long photoId, String email); Optional<Partage> findByPhoto_IdAndUtilisateur_Email(Long photoId, String email);
int countByPhoto_Id(Long photoId);
} }

View File

@@ -14,4 +14,6 @@ public interface PartageService {
boolean canComment(Long photoId, String email); boolean canComment(Long photoId, String email);
boolean canAdmin(Long photoId, String email); boolean canAdmin(Long photoId, String email);
void updatePermission(Long photoId, String targetEmail, String newPermission, String ownerEmail); void updatePermission(Long photoId, String targetEmail, String newPermission, String ownerEmail);
int countShares(Long photoId);
} }

View File

@@ -140,5 +140,9 @@ public class PartageServiceImpl implements PartageService {
partageRepository.save(partage); partageRepository.save(partage);
} }
@Override
public int countShares(Long photoId) {
return partageRepository.countByPhoto_Id(photoId);
}
} }

View File

@@ -41,11 +41,17 @@
</div> </div>
<h2>Mes photos partagées</h2> <h2>Mes photos partagées</h2>
<div> <div style="display:flex; gap:20px; flex-wrap:wrap;">
<a th:each="p : ${mesPhotosPartagees.content}" <div th:each="p : ${mesPhotosPartagees.content}">
th:href="@{'/photo/' + ${p.id}}"> <a th:href="@{'/photo/' + ${p.id}}">
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"/> <img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"
</a> style="display:block; border:1px solid #ccc;"/>
</a>
<!--compteur de partages -->
<div style="font-size:0.9em; color:#555; margin-top:4px;">
<span th:text="${shareCounts[p.id]} + ' partage(s)'"></span>
</div>
</div>
</div> </div>
<div> <div>
<a th:if="${mesPhotosPartagees.hasPrevious()}" <a th:if="${mesPhotosPartagees.hasPrevious()}"

View File

@@ -41,11 +41,17 @@
</div> </div>
<h2>Mes photos partagées</h2> <h2>Mes photos partagées</h2>
<div> <div style="display:flex; gap:20px; flex-wrap:wrap;">
<a th:each="p : ${mesPhotosPartagees.content}" <div th:each="p : ${mesPhotosPartagees.content}">
th:href="@{'/photo/' + ${p.id}}"> <a th:href="@{'/photo/' + ${p.id}}">
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"/> <img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"
</a> style="display:block; border:1px solid #ccc;"/>
</a>
<!--compteur de partages -->
<div style="font-size:0.9em; color:#555; margin-top:4px;">
<span th:text="${shareCounts[p.id]} + ' partage(s)'"></span>
</div>
</div>
</div> </div>
<div> <div>
<a th:if="${mesPhotosPartagees.hasPrevious()}" <a th:if="${mesPhotosPartagees.hasPrevious()}"