indev
This commit is contained in:
@ -13,10 +13,12 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import ovh.herisson.Clyde.Repositories.NotificationRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Tables.Notification.Status;
|
||||
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@ -24,6 +26,7 @@ import ovh.herisson.Clyde.Tables.User;
|
||||
public class NotificationController {
|
||||
|
||||
private AuthenticatorService authServ;
|
||||
private NotificationRepository notifRepo;
|
||||
|
||||
@GetMapping("/notifications")
|
||||
public ResponseEntity<List<Notification>> getNotifications(@RequestHeader("Authorization") String token){
|
||||
@ -37,8 +40,13 @@ public class NotificationController {
|
||||
}
|
||||
|
||||
@PostMapping("/notifications/{id}")
|
||||
public ResponseStatus archiveNotification(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
return null;
|
||||
public ResponseEntity<Notification> archiveNotification(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
Notification n = notifRepo.findById(id).orElse(null);
|
||||
if(u == null || n.getUser() != u){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
n.setStatus(Status.Archived);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user