indev
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m24s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s

This commit is contained in:
2024-04-19 20:22:31 +02:00
parent f14d41f04d
commit 0b9227a822
5 changed files with 48 additions and 10 deletions

View File

@ -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);
}
}