18
18
import java .time .LocalDateTime ;
19
19
import java .util .List ;
20
20
import java .util .Optional ;
21
+ import java .util .stream .Collectors ;
21
22
22
23
import static com .querydsl .core .group .GroupBy .groupBy ;
23
24
import static com .selfrunner .gwalit .domain .board .entity .QBoard .board ;
@@ -34,31 +35,40 @@ public class BoardRepositoryImpl implements BoardRepositoryCustom {
34
35
35
36
@ Override
36
37
public Slice <BoardMetaRes > findBoardPaginationByCategory (Member m , Long lectureId , BoardCategory category , Long cursor , LocalDateTime cursorCreatedAt , Pageable pageable ) {
37
- List <BoardMetaRes > content ;
38
+ List <BoardMetaRes > boardMetaResList ;
38
39
if (m .getType ().equals (MemberType .TEACHER )) {
39
- content = queryFactory .selectFrom (board )
40
+ boardMetaResList = queryFactory .selectFrom (board )
40
41
.leftJoin (lecture ).on (board .lecture .lectureId .eq (lecture .lectureId ))
41
42
.leftJoin (member ).on (board .member .memberId .eq (member .memberId ))
42
43
.leftJoin (reply ).on (board .boardId .eq (reply .board .boardId ))
43
- .where (board .lecture .lectureId .eq (lectureId ), eqCursorAndCursorCreatedAt (cursor , cursorCreatedAt ), checkCategory (category ), board .deletedAt .isNull (), reply . isNull (). or ( reply . deletedAt . isNull (). and ( reply . isNotNull ())) )
44
+ .where (board .lecture .lectureId .eq (lectureId ), eqCursorAndCursorCreatedAt (cursor , cursorCreatedAt ), checkCategory (category ), board .deletedAt .isNull ())
44
45
.orderBy (board .createdAt .desc (), board .boardId .asc ())
45
46
.groupBy (board .boardId )
46
47
.limit (pageable .getPageSize () + 1 )
47
48
.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 )));
48
49
49
50
}
50
51
else {
51
- content = queryFactory .selectFrom (board )
52
+ boardMetaResList = queryFactory .selectFrom (board )
52
53
.leftJoin (lecture ).on (board .lecture .lectureId .eq (lecture .lectureId ))
53
54
.leftJoin (member ).on (board .member .memberId .eq (member .memberId ))
54
55
.leftJoin (reply ).on (board .boardId .eq (reply .board .boardId ))
55
- .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 ())) )
56
+ .where (board .lecture .lectureId .eq (lectureId ), eqCursorAndCursorCreatedAt (cursor , cursorCreatedAt ), board .isPublic .eq (Boolean .TRUE ).or (checkWriter (m .getMemberId ())), checkCategory (category ), board .deletedAt .isNull ())
56
57
.orderBy (board .createdAt .desc (), board .boardId .asc ())
57
58
.groupBy (board .boardId )
58
59
.limit (pageable .getPageSize () + 1 )
59
60
.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 )));
60
61
}
61
62
63
+ List <BoardMetaRes > content = boardMetaResList .stream ()
64
+ .map (boardMetaRes -> {
65
+ Long replyCount = queryFactory .select (reply .count ())
66
+ .from (reply )
67
+ .where (reply .board .boardId .eq (boardMetaRes .getBoardId ()), reply .deletedAt .isNull ())
68
+ .fetchFirst ();
69
+ 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 ());
70
+ })
71
+ .collect (Collectors .toList ());
62
72
63
73
// 다음 페이지 존재 여부 계산
64
74
boolean hasNext = false ;
0 commit comments