Skip to content

Commit

Permalink
Update search endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
fizzy-fifs committed Oct 26, 2024
1 parent 69f123c commit 9feb5f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ResponseEntity<Object> findById(@PathVariable("groupId") String groupId)

@GetMapping(path = "/search/{searchTerm}/{userId}")
@Operation(summary = "Search for a group")
public ResponseEntity<Object> search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException {
public ResponseEntity<String> search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException {
return groupService.search(searchTerm, userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public ResponseEntity<Object> findById(String groupId) throws JsonProcessingExce
return ResponseEntity.ok(groupJson);
}

public ResponseEntity<Object> search(String searchTerm, String userId) {
User user = userRepository.findById(new ObjectId(userId));
public ResponseEntity<String> 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");
Expand Down Expand Up @@ -226,9 +226,10 @@ public ResponseEntity<Object> search(String searchTerm, String userId) {

List<Group> 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<Object> inviteUsers(String groupId, String invitingUserId, List<String> invitedUsersIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public ResponseEntity<String> findMultipleByPhoneNumberOrEmail(@RequestBody User

@GetMapping(path = "/search/{searchTerm}/{userId}")
@Operation(summary = "Search for a user")
public ResponseEntity<Object> search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) {
public ResponseEntity<String> search(@PathVariable("searchTerm") String searchTerm, @PathVariable("userId") String userId) throws JsonProcessingException {
return userService.search(searchTerm, userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public ResponseEntity<String> findMultipleByPhoneNumberOrEmail(UserLookupModel u
return ResponseEntity.ok(usersJson);
}

public ResponseEntity<Object> search(String searchTerm, String userId) {
public ResponseEntity<String> search(String searchTerm, String userId) throws JsonProcessingException {
User user = findSingleUserByIdInCacheOrDatabase(userId);

if (user == null) {
Expand Down Expand Up @@ -472,7 +472,9 @@ public ResponseEntity<Object> search(String searchTerm, String userId) {
users.remove(user);
users.removeIf(u -> u.getEmail().equals("[email protected]"));
updateSingleUserInCacheAndDatabase(user);
return ResponseEntity.ok(users);

String usersJson = mapper.writeValueAsString(users);
return ResponseEntity.ok(usersJson);
}

public ResponseEntity<String> findById(String id) throws JsonProcessingException {
Expand Down

0 comments on commit 9feb5f9

Please sign in to comment.