Skip to content

Commit

Permalink
[tomato-market/plan#22] Controller 및 Test 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunuk17 committed Nov 10, 2023
1 parent 4f41109 commit 9fbadf8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/main/java/com/tomato/market/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,35 @@ public ResponseDto<FavoriteDto> getFavorite(String userId, Integer postNum) {
}

@GetMapping("/board/favorite/list")
public ResponseDto<List<FavoriteDto>> getFavoriteList(String userId) {
public ResponseDto<PostListResponseDto> getFavoriteList(String userId) {
logger.info("BoardController.getFavoriteList() is called");

// 관심 목록 번호 조회
List<FavoriteDto> favoriteDtoList = boardService.getFavoriteList(userId);
logger.info("BoardController.getFavoriteList() : 관심 목록 조회 성공");

return ResponseDto.<List<FavoriteDto>>builder()
// 관심 목록에 대한 PostList 조회
// fovoriteList에 대한 가공 -> 조회
List<PostDto> postDtoList = new ArrayList<>();
for (FavoriteDto favoriteDto : favoriteDtoList) {
postDtoList.add(boardService.getPost(favoriteDto.getPostNum()));
}

// PostList에 대한 ImageList 조회
List<ImageDto> imageDtoList = new ArrayList<>();
for (PostDto postDto : postDtoList) {
imageDtoList.add(boardService.getPostImage(postDto.getPostNum()));
}

PostListResponseDto responseDto = PostListResponseDto.builder()
.postList(postDtoList)
.imageList(imageDtoList)
.build();

return ResponseDto.<PostListResponseDto>builder()
.status(HttpStatus.OK)
.message("관심 목록 조회 성공")
.data(favoriteDtoList)
.data(responseDto) // 어떤 형식으로 넘기지?
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ public List<FavoriteDto> getFavoriteList(String userId) {
logger.info("BoardServiceImpl.getFavoriteList() : 관심 목록 조회 성공");
List<FavoriteDto> favoriteDtoList = new ArrayList<>();
for (FavoriteEntity favoriteEntity : favoriteEntities) {
favoriteDtoList.add(FavoriteDto.toFavoriteDto(favoriteEntity));
if (favoriteEntity.getStatus() == 1) {
// JPA로 바꿔도 가능
favoriteDtoList.add(FavoriteDto.toFavoriteDto(favoriteEntity));
}
}
return favoriteDtoList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,19 @@ void getFavoriteFailure() throws Exception {
@DisplayName("게시글_관심_목록_조회_성공")
void getFavoriteListSuccess() throws Exception {
given(boardService.getFavoriteList(userId)).willReturn(favoriteDtoList);
given(boardService.getPost(postNum)).willReturn(postDto);
given(boardService.getPostImage(postNum)).willReturn(imageDto);

mockMvc.perform(get("/api/board/favorite/list").param("userId", userId))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is("관심 목록 조회 성공")))
.andExpect(jsonPath("$.data.postList").exists())
.andExpect(jsonPath("$.data.imageList").exists())
.andDo(print());

verify(boardService).getFavoriteList(userId);
verify(boardService, times(2)).getPost(postNum);
verify(boardService, times(2)).getPostImage(postNum);
}

@Test
Expand Down

0 comments on commit 9fbadf8

Please sign in to comment.