From 881b30e5c9de0823496c608204728637e5aa49c5 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Wed, 17 Apr 2024 12:00:52 +0200 Subject: [PATCH] indev --- .../EndPoints/NotificationController.java | 44 +++++++++++ .../herisson/Clyde/Tables/Notification.java | 37 +++++++++ .../java/ovh/herisson/Clyde/Tables/User.java | 77 ++----------------- 3 files changed, 86 insertions(+), 72 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java new file mode 100644 index 0000000..7dac27a --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/NotificationController.java @@ -0,0 +1,44 @@ +package ovh.herisson.Clyde.EndPoints; + +import java.util.List; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import lombok.AllArgsConstructor; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Tables.Notification; +import ovh.herisson.Clyde.Tables.User; + +@RestController +@AllArgsConstructor +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class NotificationController { + + private AuthenticatorService authServ; + + @GetMapping("/notifications") + public ResponseEntity> getNotifications(@RequestHeader("Authorization") String token){ + User u = authServ.getUserFromToken(token); + if(u == null){ + return new UnauthorizedResponse<>(null); + } + List n = u.getNotifications(); + return new ResponseEntity<>(n, HttpStatus.OK); + + } + + @PostMapping("/notifications/{id}") + public ResponseStatus archiveNotification(@RequestHeader("Authorization") String token, @PathVariable long id){ + return null; + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java new file mode 100644 index 0000000..36ddaa5 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Notification.java @@ -0,0 +1,37 @@ +package ovh.herisson.Clyde.Tables; + +import java.util.Date; + +import org.hibernate.annotations.CreationTimestamp; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import lombok.Data; + +@Data +@Entity +public class Notification { + + private enum Status { + Unread, + Read, + } + + @Id + private int id; + + private String Subject; + + private String body; + + private Status status; + + private String link; + + @ManyToOne + private User user; + + @CreationTimestamp + private Date creation; +} 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 2badd32..be615f0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -1,6 +1,7 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import lombok.Data; import ovh.herisson.Clyde.Tables.Msg.Discussion; import ovh.herisson.Clyde.Tables.Msg.Message; @@ -10,6 +11,7 @@ import java.util.List; @Entity @Table(name = "Users") +@Data public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -25,6 +27,9 @@ public class User { private ovh.herisson.Clyde.Tables.Role role; private String password; + @OneToMany(mappedBy = "user") + private List notifications; + ////// Extension Messagerie ///// @OneToMany(mappedBy = "author", cascade = CascadeType.ALL) private List msgs; @@ -60,76 +65,4 @@ public class User { this.password = password; this.role = Role.Student; } - public User() {} - - public Long getRegNo(){ - return this.regNo; - } - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public Date getBirthDate() { - return birthDate; - } - - public void setBirthDate(Date birthDate) { - this.birthDate = birthDate; - } - - public String getProfilePictureUrl(){return this.profilePictureUrl;} - - public void setProfilePictureUrl(String profilePictureUrl){ - this.profilePictureUrl = profilePictureUrl; - } - public ovh.herisson.Clyde.Tables.Role getRole() { - return role; - } - - public void setRole(ovh.herisson.Clyde.Tables.Role role) { - this.role = role; - } - public String getPassword(){ - return password; - } - - public void setPassword(String password) { - this.password = password; - } }