indev
This commit is contained in:
		| @ -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<List<Notification>> getNotifications(@RequestHeader("Authorization") String token){ | ||||||
|  | 		User u = authServ.getUserFromToken(token); | ||||||
|  | 		if(u == null){ | ||||||
|  |             return new UnauthorizedResponse<>(null); | ||||||
|  | 		} | ||||||
|  | 		List<Notification> n = u.getNotifications(); | ||||||
|  | 		return new ResponseEntity<>(n, HttpStatus.OK); | ||||||
|  |  | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@PostMapping("/notifications/{id}") | ||||||
|  | 	public ResponseStatus archiveNotification(@RequestHeader("Authorization") String token, @PathVariable long id){ | ||||||
|  | 		return null; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -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; | ||||||
|  | } | ||||||
| @ -1,6 +1,7 @@ | |||||||
| package ovh.herisson.Clyde.Tables; | package ovh.herisson.Clyde.Tables; | ||||||
|  |  | ||||||
| import jakarta.persistence.*; | import jakarta.persistence.*; | ||||||
|  | import lombok.Data; | ||||||
| import ovh.herisson.Clyde.Tables.Msg.Discussion; | import ovh.herisson.Clyde.Tables.Msg.Discussion; | ||||||
| import ovh.herisson.Clyde.Tables.Msg.Message; | import ovh.herisson.Clyde.Tables.Msg.Message; | ||||||
|  |  | ||||||
| @ -10,6 +11,7 @@ import java.util.List; | |||||||
|  |  | ||||||
| @Entity | @Entity | ||||||
| @Table(name = "Users") | @Table(name = "Users") | ||||||
|  | @Data | ||||||
| public class User { | public class User { | ||||||
|     @Id |     @Id | ||||||
|     @GeneratedValue(strategy = GenerationType.AUTO) |     @GeneratedValue(strategy = GenerationType.AUTO) | ||||||
| @ -25,6 +27,9 @@ public class User { | |||||||
|     private ovh.herisson.Clyde.Tables.Role role; |     private ovh.herisson.Clyde.Tables.Role role; | ||||||
|     private String password; |     private String password; | ||||||
|  |  | ||||||
|  | 	@OneToMany(mappedBy = "user") | ||||||
|  | 	private List<Notification> notifications;  | ||||||
|  |  | ||||||
| 	////// Extension Messagerie ///// | 	////// Extension Messagerie ///// | ||||||
| 	@OneToMany(mappedBy = "author", cascade = CascadeType.ALL) | 	@OneToMany(mappedBy = "author", cascade = CascadeType.ALL) | ||||||
| 	private List<Message> msgs; | 	private List<Message> msgs; | ||||||
| @ -60,76 +65,4 @@ public class User { | |||||||
|         this.password = password; |         this.password = password; | ||||||
|         this.role = Role.Student; |         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; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user