Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[API] 2 identical end-points #6324" #278

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions core/src/main/java/greencity/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,40 @@ public UserAndAllFriendsWithOnlineStatusDto getUserAndAllFriendsWithOnlineStatus
return userService.getAllFriendsWithTheOnlineStatus(userId, pageable);
}

/**
* Method find user by principal.
*
* @return {@link ResponseEntity}.
* @author Orest Mamchuk
*/
@ApiOperation(value = "Find current user by principal")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
})
@GetMapping("/findByEmail")
public ResponseEntity<UserVO> findByEmail(@RequestParam String email) {
return ResponseEntity.status(HttpStatus.OK).body(userService.findByEmail(email));
}

/**
* Get {@link UserVO} by id.
*
* @return {@link UserUpdateDto}.
* @author Orest Mamchuk
*/
@ApiOperation(value = "Get User by id")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
})
@GetMapping("/findById")
public ResponseEntity<UserVO> findById(@RequestParam Long id) {
return ResponseEntity.status(HttpStatus.OK).body(userService.findById(id));
}

/**
* Method that allow you to find {@link UserVO} by Id.
*
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/java/greencity/controller/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -404,6 +406,31 @@ void searchTest() throws Exception {
verify(userService).search(pageable, userViewDto);
}

@Test
void findByEmailTest() throws Exception {
UserVO userVO = ModelUtils.getUserVO();
when(userService.findByEmail(TestConst.EMAIL)).thenReturn(userVO);
mockMvc.perform(get(userLink + "/findByEmail")
.param("email", TestConst.EMAIL))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1L))
.andExpect(jsonPath("$.name").value(TestConst.NAME))
.andExpect(jsonPath("$.email").value(TestConst.EMAIL));
}

@Test
void findByIdTest() throws Exception {
UserVO userVO = ModelUtils.getUserVO();
when(userService.findById(1L)).thenReturn(userVO);
mockMvc.perform(get(userLink + "/findById")
.param("id", "1"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.id").value(1L))
.andExpect(jsonPath("$.name").value(TestConst.NAME))
.andExpect(jsonPath("$.email").value(TestConst.EMAIL));
}

@Test
void findUserForAchievementTest() throws Exception {
UserVOAchievement userVOAchievement = UserVOAchievement.builder()
Expand Down
Loading