From 260191d790da03c8ebb92850eae085e19a0f39ae Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 21 Apr 2024 20:15:47 +0200 Subject: [PATCH] archiving --- .../Clyde/EndPoints/NotificationController.java | 13 +++++++++++-- .../ovh/herisson/Clyde/Tables/Notification.java | 1 + .../main/java/ovh/herisson/Clyde/Tables/User.java | 8 -------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java index 536f76b..106b48a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java @@ -1,5 +1,7 @@ package ovh.herisson.Clyde.EndPoints; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.springframework.http.HttpStatus; @@ -34,8 +36,13 @@ public class NotificationController { if(u == null){ return new UnauthorizedResponse<>(null); } - List n = u.getNotifications(); - return new ResponseEntity<>(n, HttpStatus.OK); + ArrayList ret = new ArrayList<>(); + for (Notification n : u.getNotifications()) { + if(!n.getStatus().equals(Status.Archived)){ + ret.add(n); + } + } + return new ResponseEntity<>(ret, HttpStatus.OK); } @@ -46,7 +53,9 @@ public class NotificationController { if(u == null || n.getUser() != u){ return new UnauthorizedResponse<>(null); } + n.setStatus(Status.Archived); + notifRepo.save(n); return new ResponseEntity<>(HttpStatus.OK); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java index 1b7ab53..1ccddaf 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java @@ -39,6 +39,7 @@ public class Notification { private String link; @ManyToOne + @JsonIgnore private User user; @CreationTimestamp diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index e2a0c27..3c9b6ec 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -78,12 +78,4 @@ public class User { this.password = password; this.role = Role.Student; } - - public List getNotifications(){ - for(Notification n: this.notifications){ - if(n.getStatus() == Status.Archived) - this.notifications.remove(n); - } - return this.notifications; - } }