File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
src/main/java/com/somemore/community/repository/comment Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 11package com .somemore .community .repository .comment ;
22
33import com .somemore .community .domain .CommunityComment ;
4+ import com .somemore .community .repository .mapper .CommunityCommentView ;
45
6+ import java .util .List ;
57import java .util .Optional ;
68
79public interface CommunityCommentRepository {
810 CommunityComment save (CommunityComment communityComment );
911 Optional <CommunityComment > findById (Long id );
12+ List <CommunityCommentView > findCommentsByBoardId (Long boardId );
1013 boolean existsById (Long id );
1114 default boolean doesNotExistById (Long id ) {
1215 return !existsById (id );
Original file line number Diff line number Diff line change 11package com .somemore .community .repository .comment ;
22
3+ import com .querydsl .core .types .Projections ;
34import com .querydsl .jpa .impl .JPAQueryFactory ;
45import com .somemore .community .domain .CommunityComment ;
56import com .somemore .community .domain .QCommunityComment ;
7+ import com .somemore .community .repository .mapper .CommunityCommentView ;
8+ import com .somemore .volunteer .domain .QVolunteer ;
69import lombok .RequiredArgsConstructor ;
710import org .springframework .stereotype .Repository ;
811
12+ import java .util .List ;
913import java .util .Optional ;
1014
1115@ RequiredArgsConstructor
@@ -31,6 +35,21 @@ public Optional<CommunityComment> findById(Long id) {
3135 .fetchOne ());
3236 }
3337
38+ public List <CommunityCommentView > findCommentsByBoardId (Long boardId ) {
39+ QCommunityComment communityComment = QCommunityComment .communityComment ;
40+ QVolunteer volunteer = QVolunteer .volunteer ;
41+
42+ return queryFactory
43+ .select (Projections .constructor (CommunityCommentView .class ,
44+ communityComment ,
45+ volunteer .nickname ))
46+ .from (communityComment )
47+ .join (volunteer ).on (communityComment .writerId .eq (volunteer .id ))
48+ .where (communityComment .communityBoardId .eq (boardId ))
49+ .orderBy (communityComment .parentCommentId .asc ().nullsFirst (), communityComment .createdAt .asc ())
50+ .fetch ();
51+ }
52+
3453 @ Override
3554 public boolean existsById (Long id ) {
3655 QCommunityComment communityComment = QCommunityComment .communityComment ;
You can’t perform that action at this time.
0 commit comments