Skip to content

Commit

Permalink
Revert "[API] 2 identical end-points #6324"
Browse files Browse the repository at this point in the history
  • Loading branch information
ABbondar authored Sep 12, 2023
1 parent eb7a03b commit 8dc3dad
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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

0 comments on commit 8dc3dad

Please sign in to comment.