diff --git a/src/main/java/com/example/holidayplanner/group/GroupController.java b/src/main/java/com/example/holidayplanner/group/GroupController.java index 561d391..4ae445e 100644 --- a/src/main/java/com/example/holidayplanner/group/GroupController.java +++ b/src/main/java/com/example/holidayplanner/group/GroupController.java @@ -68,7 +68,7 @@ public ResponseEntity findById(@PathVariable("groupId") String groupId) @GetMapping(path = "/search/{searchTerm}/{userId}") @Operation(summary = "Search for a group") - public ResponseEntity search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException { + public ResponseEntity search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException { return groupService.search(searchTerm, userId); } diff --git a/src/main/java/com/example/holidayplanner/group/GroupService.java b/src/main/java/com/example/holidayplanner/group/GroupService.java index 50057c1..0643a93 100644 --- a/src/main/java/com/example/holidayplanner/group/GroupService.java +++ b/src/main/java/com/example/holidayplanner/group/GroupService.java @@ -195,8 +195,8 @@ public ResponseEntity findById(String groupId) throws JsonProcessingExce return ResponseEntity.ok(groupJson); } - public ResponseEntity search(String searchTerm, String userId) { - User user = userRepository.findById(new ObjectId(userId)); + public ResponseEntity search(String searchTerm, String userId) throws JsonProcessingException { + User user = userService.findSingleUserByIdInCacheOrDatabase(userId); if (user == null) { return ResponseEntity.badRequest().body("User with id " + userId + " does not exist"); @@ -226,9 +226,10 @@ public ResponseEntity search(String searchTerm, String userId) { List groups = mongoTemplate.find(searchQuery, Group.class); - userRepository.save(user); + userService.updateSingleUserInCacheAndDatabase(user); - return ResponseEntity.ok(groups); + String groupsJson = mapper.writeValueAsString(groups); + return ResponseEntity.ok(groupsJson); } public ResponseEntity inviteUsers(String groupId, String invitingUserId, List invitedUsersIds) { diff --git a/src/main/java/com/example/holidayplanner/user/UserController.java b/src/main/java/com/example/holidayplanner/user/UserController.java index c1536a9..9003e17 100644 --- a/src/main/java/com/example/holidayplanner/user/UserController.java +++ b/src/main/java/com/example/holidayplanner/user/UserController.java @@ -108,7 +108,7 @@ public ResponseEntity findMultipleByPhoneNumberOrEmail(@RequestBody User @GetMapping(path = "/search/{searchTerm}/{userId}") @Operation(summary = "Search for a user") - public ResponseEntity search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) { + public ResponseEntity search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException { return userService.search(searchTerm, userId); } diff --git a/src/main/java/com/example/holidayplanner/user/UserService.java b/src/main/java/com/example/holidayplanner/user/UserService.java index cd27a9e..81de47b 100644 --- a/src/main/java/com/example/holidayplanner/user/UserService.java +++ b/src/main/java/com/example/holidayplanner/user/UserService.java @@ -434,7 +434,7 @@ public ResponseEntity findMultipleByPhoneNumberOrEmail(UserLookupModel u return ResponseEntity.ok(usersJson); } - public ResponseEntity search(String searchTerm, String userId) { + public ResponseEntity search(String searchTerm, String userId) throws JsonProcessingException { User user = findSingleUserByIdInCacheOrDatabase(userId); if (user == null) { @@ -472,7 +472,9 @@ public ResponseEntity search(String searchTerm, String userId) { users.remove(user); users.removeIf(u -> u.getEmail().equals("admin@mail.com")); updateSingleUserInCacheAndDatabase(user); - return ResponseEntity.ok(users); + + String usersJson = mapper.writeValueAsString(users); + return ResponseEntity.ok(usersJson); } public ResponseEntity findById(String id) throws JsonProcessingException {