From 2bdffe6ab4962d660a6302e114b2028f8f439aef Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 29 Mar 2024 14:30:46 +0100 Subject: [PATCH] remove member of a discussion --- .../Clyde/EndPoints/Msg/MessagesController.java | 16 +++++++++++++++- .../herisson/Clyde/Tables/Msg/Discussion.java | 4 ++++ frontend/src/Apps/Msg.vue | 17 +++++++++++++++-- frontend/src/rest/msg.js | 4 ++++ 4 files changed, 38 insertions(+), 3 deletions(-) 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 8cee27c..591e172 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 @@ -65,7 +65,7 @@ public class MessagesController { } @PatchMapping("/discussion/{id}/add") - public ResponseEntity AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){ + public ResponseEntity invite(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){ User user = authServ.getUserFromToken(token); if(user == null){ return new UnauthorizedResponse<>(null); @@ -78,6 +78,20 @@ public class MessagesController { return new ResponseEntity<>(disc, HttpStatus.OK); } + @PatchMapping("/discussion/{id}/remove") + public ResponseEntity removeMember(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){ + User user = authServ.getUserFromToken(token); + if(user == null){ + return new UnauthorizedResponse<>(null); + } + + Discussion disc = discRepo.findById(id).orElse(null); + User member = userServ.getUserById(data.getRegNo()); + disc.delMember(member); + 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); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java index e98bd1e..ee0912e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java @@ -55,4 +55,8 @@ public class Discussion{ public void addMember(User user) { members.add(user); } + + public void delMember(User user) { + members.remove(user); + } } diff --git a/frontend/src/Apps/Msg.vue b/frontend/src/Apps/Msg.vue index b74f980..a5aa1f4 100644 --- a/frontend/src/Apps/Msg.vue +++ b/frontend/src/Apps/Msg.vue @@ -7,7 +7,7 @@