FEAT : ajout compteur de partage
This commit is contained in:
@@ -20,6 +20,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class PhotoController {
|
||||
@@ -84,7 +86,6 @@ public class PhotoController {
|
||||
|
||||
|
||||
/* ========================== MES PHOTOS ========================== */
|
||||
|
||||
@GetMapping("/mes-photos")
|
||||
public String mesPhotos(
|
||||
@RequestParam(defaultValue = "0") int pagePrivees,
|
||||
@@ -92,30 +93,32 @@ public class PhotoController {
|
||||
@RequestParam(defaultValue = "0") int pagePartagees,
|
||||
@RequestParam(defaultValue = "0") int pageMesPartagees,
|
||||
Authentication auth, Model model) {
|
||||
|
||||
String email = auth.getName();
|
||||
|
||||
model.addAttribute("photosPrivees",
|
||||
photoService.listPrivatePhotos(email, pagePrivees, 12));
|
||||
|
||||
model.addAttribute("photosPubliques",
|
||||
photoService.listPublicPhotos(email, pagePubliques, 12));
|
||||
|
||||
model.addAttribute("photosPartagees",
|
||||
photoService.listSharedWith(email, pagePartagees, 12));
|
||||
|
||||
model.addAttribute("mesPhotosPartagees",
|
||||
photoService.listSharedPhotos(email, pageMesPartagees, 12));
|
||||
|
||||
// Récupération des pages
|
||||
Page<PhotoDTO> photosPrivees = photoService.listPrivatePhotos(email, pagePrivees, 12);
|
||||
Page<PhotoDTO> photosPubliques = photoService.listPublicPhotos(email, pagePubliques, 12);
|
||||
Page<PhotoDTO> photosPartagees = photoService.listSharedWith(email, pagePartagees, 12);
|
||||
Page<PhotoDTO> mesPhotosPartagees = photoService.listSharedPhotos(email, pageMesPartagees, 12);
|
||||
// Calcul du nombre de partages pour TOUTES mes photos SHARED
|
||||
Map<Long, Integer> shareCounts = new HashMap<>();
|
||||
mesPhotosPartagees.getContent().forEach(p -> {
|
||||
shareCounts.put(p.getId(), partageService.countShares(p.getId()));
|
||||
});
|
||||
// Envoi au model
|
||||
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("pagePubliques", pagePubliques);
|
||||
model.addAttribute("pagePartagees", pagePartagees);
|
||||
model.addAttribute("pageMesPartagees", pageMesPartagees);
|
||||
|
||||
return "mes-photos";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ========================== GALERIE ========================== */
|
||||
|
||||
@GetMapping("/galerie")
|
||||
|
||||
@@ -12,4 +12,5 @@ public interface PartageRepository extends JpaRepository<Partage, Long> {
|
||||
boolean existsByPhoto_IdAndUtilisateur_Email(Long photoId, String email);
|
||||
List<Partage> findByUtilisateur_Email(String email);
|
||||
Optional<Partage> findByPhoto_IdAndUtilisateur_Email(Long photoId, String email);
|
||||
int countByPhoto_Id(Long photoId);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ public interface PartageService {
|
||||
boolean canComment(Long photoId, String email);
|
||||
boolean canAdmin(Long photoId, String email);
|
||||
void updatePermission(Long photoId, String targetEmail, String newPermission, String ownerEmail);
|
||||
int countShares(Long photoId);
|
||||
|
||||
}
|
||||
|
||||
@@ -140,5 +140,9 @@ public class PartageServiceImpl implements PartageService {
|
||||
partageRepository.save(partage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countShares(Long photoId) {
|
||||
return partageRepository.countByPhoto_Id(photoId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,11 +41,17 @@
|
||||
</div>
|
||||
|
||||
<h2>Mes photos partagées</h2>
|
||||
<div>
|
||||
<a th:each="p : ${mesPhotosPartagees.content}"
|
||||
th:href="@{'/photo/' + ${p.id}}">
|
||||
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"/>
|
||||
<div style="display:flex; gap:20px; flex-wrap:wrap;">
|
||||
<div th:each="p : ${mesPhotosPartagees.content}">
|
||||
<a th:href="@{'/photo/' + ${p.id}}">
|
||||
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"
|
||||
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>
|
||||
<a th:if="${mesPhotosPartagees.hasPrevious()}"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -41,11 +41,17 @@
|
||||
</div>
|
||||
|
||||
<h2>Mes photos partagées</h2>
|
||||
<div>
|
||||
<a th:each="p : ${mesPhotosPartagees.content}"
|
||||
th:href="@{'/photo/' + ${p.id}}">
|
||||
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"/>
|
||||
<div style="display:flex; gap:20px; flex-wrap:wrap;">
|
||||
<div th:each="p : ${mesPhotosPartagees.content}">
|
||||
<a th:href="@{'/photo/' + ${p.id}}">
|
||||
<img th:src="@{'/photo/' + ${p.id} + '/raw'}" width="120"
|
||||
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>
|
||||
<a th:if="${mesPhotosPartagees.hasPrevious()}"
|
||||
|
||||
Reference in New Issue
Block a user