Skip to content

Commit

Permalink
Merge branch 'dev' into feature/30_category
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunuk17 authored Nov 16, 2023
2 parents 92c6cc4 + 4a843a7 commit d2ed996
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/com/tomato/market/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,31 @@ public ResponseDto<PostDto> updateStatus(@RequestBody PostDto postDto) {
.data(result)
.build();
}

// 판매 목록
@GetMapping("/board/sellList")
public ResponseDto<PostListResponseDto> getSellList(String userId) {
logger.info("BoardController.getSellList() is called");

List<PostDto> postDtoList = boardService.getSellList(userId);
logger.info("BoardController.getSellList() : 판매 목록 조회 성공");

// 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(responseDto)
.build();
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/tomato/market/dao/BoardDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface BoardDao {
FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum);

List<FavoriteEntity> findByUserId(String userId);

List<PostEntity> findPostByUserId(String userId);
}
13 changes: 13 additions & 0 deletions src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,17 @@ public List<FavoriteEntity> findByUserId(String userId) {
logger.info("BoardDaoImpl.findByUserId() : 데이터 조회 성공");
return favoriteEntities;
}

@Override
public List<PostEntity> findPostByUserId(String userId) {
logger.info("BoardDaoImpl.findPostByUserId() is called");
List<PostEntity> postEntities = postRepository.findByUserId(userId);
if (postEntities == null) {
logger.warn("BoardDaoImpl.findPostByUserId : 데이터 조회 실패");
return null;
}

logger.info("BoardDaoImpl.findPostByUserId : 데이터 조회 성공");
return postEntities;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tomato.market.data.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Page;
Expand All @@ -17,4 +18,5 @@ public interface PostRepository extends JpaRepository<PostEntity, Integer> {

Optional<PostEntity> findByPostNum(Integer postNum);

List<PostEntity> findByUserId(String userId);
}
2 changes: 2 additions & 0 deletions src/main/java/com/tomato/market/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface BoardService {
PostDto updatePost(PostDto postDto);

PostDto updateStatus(PostDto postDto);

List<PostDto> getSellList(String userId);
}
19 changes: 19 additions & 0 deletions src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,23 @@ public PostDto updateStatus(PostDto postDto) {
logger.info("BoardServiceImpl.updateStatus() : 게시글 수정 성공");
return PostDto.toPostDto(result);
}

@Override
public List<PostDto> getSellList(String userId) {
logger.info("BoardServiceImpl.getSellList() is called");

List<PostEntity> postEntities = boardDao.findPostByUserId(userId);
if (postEntities == null) {
logger.warn("BoardServiceImpl.getSellList() : 판매 목록 조회 실패");
throw new BoardException("판매 목록 조회에 실패했습니다.");
}

logger.info("BoardServiceImpl.getSellList() : 판매 목록 조회 성공");
List<PostDto> postDtoList = new ArrayList<>();
for (PostEntity postEntity : postEntities) {
postDtoList.add(PostDto.toPostDto(postEntity));
}

return postDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,38 @@ void updateStatusFailure() throws Exception {

verify(boardService).updateStatus(any(PostDto.class));
}

@Test
@DisplayName("판매_목록_조회_성공")
void getSellListSuccess() throws Exception {
given(boardService.getSellList(any(String.class))).willReturn(postList);
given(boardService.getPostImage(any(Integer.class))).willReturn(imageDto);

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

verify(boardService).getSellList(any(String.class));
verify(boardService, times(2)).getPostImage(any(Integer.class));
}

@Test
@DisplayName("판매_목록_조회_실패")
void getSellListFailure() throws Exception {
given(boardService.getSellList(any(String.class))).willThrow(new BoardException("판매 목록 조회에 실패했습니다."));

mockMvc.perform(get("/api/board/sellList")
.param("userId", userId)
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is("판매 목록 조회에 실패했습니다.")))
.andDo(print());

verify(boardService).getSellList(any(String.class));
}
}
25 changes: 25 additions & 0 deletions src/test/java/com/tomato/market/service/BoardServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,29 @@ void updateStatusFailure() {
verify(boardDao).findPostByPostNum(any(Integer.class));
verify(boardDao).save(any(PostEntity.class));
}

@Test
@DisplayName("판매_목록_조회_성공")
void getSellListSuccess() {
given(boardDao.findPostByUserId(any(String.class))).willReturn(postEntities);

BoardServiceImpl boardService = new BoardServiceImpl(boardDao);
Assertions.assertEquals(boardService.getSellList(userId).toString(), postDtoList.toString());

verify(boardDao).findPostByUserId(any(String.class));
}

@Test
@DisplayName("판매_목록_조회_실패")
void getSellListFailure() {
given(boardDao.findPostByUserId(any(String.class))).willReturn(null);

BoardServiceImpl boardService = new BoardServiceImpl(boardDao);
BoardException exception = Assertions.assertThrows(BoardException.class, () -> {
boardService.getSellList(userId);
});
Assertions.assertEquals(exception.getMessage(), "판매 목록 조회에 실패했습니다.");

verify(boardDao).findPostByUserId(any(String.class));
}
}

0 comments on commit d2ed996

Please sign in to comment.