archiving
This commit is contained in:
		@ -1,5 +1,7 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.EndPoints;
 | 
					package ovh.herisson.Clyde.EndPoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.http.HttpStatus;
 | 
					import org.springframework.http.HttpStatus;
 | 
				
			||||||
@ -34,8 +36,13 @@ public class NotificationController {
 | 
				
			|||||||
		if(u == null){
 | 
							if(u == null){
 | 
				
			||||||
            return new UnauthorizedResponse<>(null);
 | 
					            return new UnauthorizedResponse<>(null);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		List<Notification> n = u.getNotifications();
 | 
							ArrayList<Notification> ret = new ArrayList<>();
 | 
				
			||||||
		return new ResponseEntity<>(n, HttpStatus.OK);
 | 
							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){
 | 
							if(u == null || n.getUser() != u){
 | 
				
			||||||
            return new UnauthorizedResponse<>(null);
 | 
					            return new UnauthorizedResponse<>(null);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		n.setStatus(Status.Archived);
 | 
							n.setStatus(Status.Archived);
 | 
				
			||||||
 | 
							notifRepo.save(n);
 | 
				
			||||||
		return new ResponseEntity<>(HttpStatus.OK);
 | 
							return new ResponseEntity<>(HttpStatus.OK);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,7 @@ public class Notification {
 | 
				
			|||||||
	private String link;
 | 
						private String link;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@ManyToOne
 | 
						@ManyToOne
 | 
				
			||||||
 | 
						@JsonIgnore
 | 
				
			||||||
	private User user;
 | 
						private User user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@CreationTimestamp
 | 
						@CreationTimestamp
 | 
				
			||||||
 | 
				
			|||||||
@ -78,12 +78,4 @@ public class User {
 | 
				
			|||||||
        this.password = password;
 | 
					        this.password = password;
 | 
				
			||||||
        this.role = Role.Student;
 | 
					        this.role = Role.Student;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
	public List<Notification> getNotifications(){
 | 
					 | 
				
			||||||
		for(Notification n: this.notifications){
 | 
					 | 
				
			||||||
			if(n.getStatus() == Status.Archived)
 | 
					 | 
				
			||||||
				this.notifications.remove(n);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return this.notifications;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user