Refactoring + Checkpoint

This commit is contained in:
DahoudG
2024-11-17 22:58:38 +00:00
parent 588984aa9c
commit 2f33b09753
10 changed files with 278 additions and 50 deletions

View File

@@ -79,14 +79,24 @@ public class FriendshipService {
*/
@Transactional
public FriendshipCreateOneResponseDTO acceptFriendRequest(UUID friendshipId) {
// Vérification de l'ID de la demande d'amitié
if (friendshipId == null) {
logger.error(String.format("[ERROR] L'ID de la demande d'amitié est nul."));
throw new IllegalArgumentException("L'ID de la demande d'amitié est nul.");
}
// Rechercher l'amitié dans la base de données
Friendship friendship = friendshipRepository.findById(friendshipId);
// Si l'amitié n'est pas trouvée, lever une exception
if (friendship == null) {
logger.error(String.format("[ERROR] Demande d'amitié introuvable pour l'ID: %s", friendshipId)); // Correctement formaté
throw new FriendshipNotFoundException("Demande d'amitié introuvable.");
}
// Vérifier que la demande n'est pas déjà acceptée
if (friendship.getStatus() == FriendshipStatus.ACCEPTED) {
logger.error("[ERROR] Demande d'amitié déjà acceptée.");
logger.error(String.format("[ERROR] Demande d'amitié déjà acceptée pour l'ID: %s", friendshipId)); // Correctement formaté
throw new IllegalArgumentException("Demande d'amitié déjà acceptée.");
}
@@ -94,7 +104,10 @@ public class FriendshipService {
friendship.setStatus(FriendshipStatus.ACCEPTED);
friendshipRepository.persist(friendship);
logger.info("[LOG] Demande d'amitié acceptée avec succès.");
// Log de succès
logger.info(String.format("[LOG] Demande d'amitié acceptée avec succès pour l'ID: %s", friendshipId)); // Correctement formaté
// Retourner la réponse avec les informations de la relation d'amitié
return new FriendshipCreateOneResponseDTO(friendship);
}
@@ -175,6 +188,7 @@ public class FriendshipService {
friend.getNom(), // Nom de l'ami
friend.getPrenoms(),
friend.getEmail(), // Email de l'ami
friend.getProfileImageUrl(), // URL de l'image de profil de l'ami
friendship.getStatus(), // Statut de la relation
friendship.getCreatedAt(), // Date de création de la relation
friendship.getUpdatedAt() // Date de mise à jour de la relation
@@ -211,6 +225,7 @@ public class FriendshipService {
friend.getNom(),
friend.getPrenoms(),
friend.getEmail(),
friend.getProfileImageUrl(),
friendship.getStatus(),
friendship.getCreatedAt(),
friendship.getUpdatedAt()