diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java index e42e8c0..a40545f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java @@ -49,12 +49,26 @@ public class MessagesController { @PatchMapping("/discussion/{id}") public ResponseEntity AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Discussion data){ - return new ResponseEntity<>(discRepo.findById(id).orElse(null), HttpStatus.OK); + User user = authServ.getUserFromToken(token); + if(user == null){ + return new UnauthorizedResponse<>(null); + } + + Discussion disc = discRepo.findById(id).orElse(null); + disc.setName(data.getName()); + discRepo.save(disc); + return new ResponseEntity<>(disc, HttpStatus.OK); } @PostMapping("/discussion/{id}") public ResponseEntity sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){ + User user = authServ.getUserFromToken(token); + if(user == null){ + return new UnauthorizedResponse<>(null); + } + Discussion disc = discRepo.findById(id).orElse(null); + msg.setAuthor(user); if(disc != null) discServ.CreateMessage(disc, msg); return new ResponseEntity<>(disc, HttpStatus.OK); diff --git a/frontend/src/Apps/Msg.vue b/frontend/src/Apps/Msg.vue index cb78eae..58e243e 100644 --- a/frontend/src/Apps/Msg.vue +++ b/frontend/src/Apps/Msg.vue @@ -7,7 +7,7 @@