Skip to content

Commit

Permalink
Fix: 과릿 1.3.5 (#412)
Browse files Browse the repository at this point in the history
* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5
  • Loading branch information
dl-00-e8 authored Jan 16, 2024
1 parent 8c5ee84 commit c8f783d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BoardReplyRes(Board board, Member member, LocalDate lessonDate, Integer r
this.category = board.getCategory();
this.status = board.getStatus();
this.fileList = fileList;
this.replyCount = replyCount;
this.replyCount = (replyCount != null) ? replyCount : 0;
this.createdAt = board.getCreatedAt();
this.modifiedAt = board.getModifiedAt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.querydsl.core.group.GroupBy.groupBy;
import static com.selfrunner.gwalit.domain.board.entity.QBoard.board;
Expand All @@ -34,31 +35,40 @@ public class BoardRepositoryImpl implements BoardRepositoryCustom {

@Override
public Slice<BoardMetaRes> findBoardPaginationByCategory(Member m, Long lectureId, BoardCategory category, Long cursor, LocalDateTime cursorCreatedAt, Pageable pageable) {
List<BoardMetaRes> content;
List<BoardMetaRes> boardMetaResList;
if (m.getType().equals(MemberType.TEACHER)) {
content = queryFactory.selectFrom(board)
boardMetaResList = queryFactory.selectFrom(board)
.leftJoin(lecture).on(board.lecture.lectureId.eq(lecture.lectureId))
.leftJoin(member).on(board.member.memberId.eq(member.memberId))
.leftJoin(reply).on(board.boardId.eq(reply.board.boardId))
.where(board.lecture.lectureId.eq(lectureId), eqCursorAndCursorCreatedAt(cursor, cursorCreatedAt), checkCategory(category), board.deletedAt.isNull(), reply.isNull().or(reply.deletedAt.isNull().and(reply.isNotNull())))
.where(board.lecture.lectureId.eq(lectureId), eqCursorAndCursorCreatedAt(cursor, cursorCreatedAt), checkCategory(category), board.deletedAt.isNull())
.orderBy(board.createdAt.desc(), board.boardId.asc())
.groupBy(board.boardId)
.limit(pageable.getPageSize() + 1)
.transform(groupBy(board.boardId).list(Projections.constructor(BoardMetaRes.class, board.boardId, lecture.lectureId, member.memberId, member.type, member.name, board.lessonId, board.title, board.body, board.category, board.status, reply.count(), board.createdAt, board.modifiedAt)));

}
else {
content = queryFactory.selectFrom(board)
boardMetaResList = queryFactory.selectFrom(board)
.leftJoin(lecture).on(board.lecture.lectureId.eq(lecture.lectureId))
.leftJoin(member).on(board.member.memberId.eq(member.memberId))
.leftJoin(reply).on(board.boardId.eq(reply.board.boardId))
.where(board.lecture.lectureId.eq(lectureId), eqCursorAndCursorCreatedAt(cursor, cursorCreatedAt), board.isPublic.eq(Boolean.TRUE).or(checkWriter(m.getMemberId())), checkCategory(category), board.deletedAt.isNull(), reply.isNull().or(reply.deletedAt.isNull().and(reply.isNotNull())))
.where(board.lecture.lectureId.eq(lectureId), eqCursorAndCursorCreatedAt(cursor, cursorCreatedAt), board.isPublic.eq(Boolean.TRUE).or(checkWriter(m.getMemberId())), checkCategory(category), board.deletedAt.isNull())
.orderBy(board.createdAt.desc(), board.boardId.asc())
.groupBy(board.boardId)
.limit(pageable.getPageSize() + 1)
.transform(groupBy(board.boardId).list(Projections.constructor(BoardMetaRes.class, board.boardId, lecture.lectureId, member.memberId, member.type, member.name, board.lessonId, board.title, board.body, board.category, board.status, reply.count(), board.createdAt, board.modifiedAt)));
}

List<BoardMetaRes> content = boardMetaResList.stream()
.map(boardMetaRes -> {
Long replyCount = queryFactory.select(reply.count())
.from(reply)
.where(reply.board.boardId.eq(boardMetaRes.getBoardId()), reply.deletedAt.isNull())
.fetchFirst();
return new BoardMetaRes(boardMetaRes.getBoardId(), boardMetaRes.getLectureId(), boardMetaRes.getMemberId(), boardMetaRes.getMemberType(), boardMetaRes.getMemberName(), boardMetaRes.getLessonId(), boardMetaRes.getTitle(), boardMetaRes.getBody(), boardMetaRes.getCategory(), boardMetaRes.getStatus(), replyCount, boardMetaRes.getCreatedAt(), boardMetaRes.getModifiedAt());
})
.collect(Collectors.toList());

// 다음 페이지 존재 여부 계산
boolean hasNext = false;
Expand Down

0 comments on commit c8f783d

Please sign in to comment.