Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public Optional<CommunityBoard> findById(Long id) {
@Override
public Page<CommunityBoardView> findCommunityBoards(Pageable pageable) {
List<CommunityBoardView> content = getCommunityBoardsQuery()
.where(QCommunityBoard.communityBoard.deleted.eq(false))
.where(isNotDeleted())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

JPAQuery<Long> countQuery = queryFactory
Expand All @@ -59,14 +61,17 @@ public Page<CommunityBoardView> findCommunityBoards(Pageable pageable) {
@Override
public Page<CommunityBoardView> findByWriterId(UUID writerId, Pageable pageable) {
List<CommunityBoardView> content = getCommunityBoardsQuery()
.where(QCommunityBoard.communityBoard.writerId.eq(writerId)
.and(QCommunityBoard.communityBoard.deleted.eq(false)))
.where(isWriter(writerId)
.and(isNotDeleted()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

JPAQuery<Long> countQuery = queryFactory
.select(communityBoard.count())
.from(communityBoard)
.where(isNotDeleted());
.where(isWriter(writerId)
.and(isNotDeleted()));

return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);
}
Expand Down Expand Up @@ -95,4 +100,6 @@ public void deleteAllInBatch() {
private BooleanExpression isNotDeleted() {
return communityBoard.deleted.eq(false);
}

private BooleanExpression isWriter(UUID writerId) {return communityBoard.writerId.eq(writerId); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public Page<CommunityCommentView> findCommentsByBoardId(Long boardId, Pageable p

JPAQuery<Long> countQuery = queryFactory
.select(communityComment.count())
.from(communityComment);
.from(communityComment)
.where(communityComment.communityBoardId.eq(boardId));

return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ void setUp() {
communityBoardRepository.save(createCommunityBoard(writerId2));

communityId1 = communityBoard1.getId();

for (int i = 1; i <= 11; i++) {
String title = "제목" + i;
CommunityBoard communityBoard = createCommunityBoard(title, writerId1);
communityBoardRepository.save(communityBoard);
}

for (int i = 1; i <= 20; i++) {
String title = "제목" + i;
CommunityBoard communityBoard = createCommunityBoard(title, writerId2);
communityBoardRepository.save(communityBoard);
}
}

@AfterEach
Expand All @@ -82,8 +94,9 @@ void getAllCommunityBoards() {

//then
assertThat(dtos).isNotNull();
assertThat(dtos.getTotalElements()).isEqualTo(2);
assertThat(dtos.getTotalElements()).isEqualTo(33);
assertThat(dtos.getSize()).isEqualTo(10);
assertThat(dtos.getTotalPages()).isEqualTo(4);
assertThat(dtos.getNumber()).isZero();
}

Expand All @@ -97,8 +110,9 @@ void getCommunityBoardsByWriter() {

//then
assertThat(dtos).isNotNull();
assertThat(dtos.getTotalElements()).isEqualTo(1);
assertThat(dtos.getTotalElements()).isEqualTo(12);
assertThat(dtos.getSize()).isEqualTo(10);
assertThat(dtos.getTotalPages()).isEqualTo(2);
assertThat(dtos.getNumber()).isZero();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CommunityCommentQueryServiceTest extends IntegrationTestSupport {
@Autowired
private DeleteCommunityCommentUseCase deleteCommunityCommentUseCase;

private Long boardId, commentId, replyId;
private Long boardId, commentId, replyId, commentId2;
UUID writerId;

@BeforeEach
Expand All @@ -53,7 +53,11 @@ void setUp() {
communityCommentRepository.save(communityComment1);
commentId = communityComment1.getId();

for (int i = 1; i <= 8; i++) {
CommunityComment communityComment2 = createCommunityComment(boardId, writerId);
communityCommentRepository.save(communityComment2);
commentId2 = communityComment2.getId();

for (int i = 1; i <= 12; i++) {
String content = "제목" + i;
CommunityComment communityComment = createCommunityComment(content, boardId, writerId);
communityCommentRepository.save(communityComment);
Expand All @@ -79,14 +83,15 @@ void getCommentsByCommunityBoardId() {

//then
assertThat(comments).isNotNull();
assertThat(comments.getTotalElements()).isEqualTo(10);
assertThat(comments.getTotalElements()).isEqualTo(15);
assertThat(comments.getSize()).isEqualTo(4);
assertThat(comments.getNumber()).isZero();
assertThat(comments.getTotalPages()).isEqualTo(4);
}

@DisplayName("삭제된 댓글의 경우 조회할 수 없다.")
@DisplayName("삭제된 대댓글의 경우 조회할 수 없다.")
@Test
void doesNotFind() {
void doesNotFindReply() {

//given
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, replyId, boardId);

Expand All @@ -95,9 +100,24 @@ void doesNotFind() {

//then
assertThat(comments).isNotNull();
assertThat(comments.getTotalElements()).isEqualTo(9);
assertThat(comments.getTotalElements()).isEqualTo(14);
assertThat(comments.getSize()).isEqualTo(4);
}

@DisplayName("대댓글이 없는 삭제된 댓글의 경우 조회할 수 없다.")
@Test
void doesNotFindCommennt() {

//given
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId2, boardId);

//when
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);

//then
assertThat(comments).isNotNull();
assertThat(comments.getTotalElements()).isEqualTo(14);
assertThat(comments.getSize()).isEqualTo(4);
assertThat(comments.getNumber()).isZero();
}

@DisplayName("대댓글이 있는 댓글의 경우 삭제된 댓글로 조회할 수 있다.")
Expand All @@ -106,13 +126,13 @@ void getCommentsByCommunityBoardIdWithDeletedComment() {

//given
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId, boardId);

//when
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);

//then
assertThat(comments).isNotNull();
assertThat(comments.getTotalElements()).isEqualTo(10);
assertThat(comments.getTotalElements()).isEqualTo(15);
assertThat(comments.getSize()).isEqualTo(4);
assertThat(comments.getNumber()).isZero();
}
}
Loading