-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/unit/daybook/domain/comment/dto/response/FindOneCommentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.unit.daybook.domain.comment.dto.response; | ||
|
||
import com.unit.daybook.domain.comment.entity.Comment; | ||
|
||
public record FindOneCommentResponse( | ||
Long commentId, | ||
String content | ||
) { | ||
public static FindOneCommentResponse from(Comment comment) { | ||
return new FindOneCommentResponse(comment.getCommentId(), comment.getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/unit/daybook/domain/comment/repository/CommentRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
package com.unit.daybook.domain.comment.repository; | ||
|
||
import java.util.List; | ||
|
||
import com.unit.daybook.domain.comment.dto.response.FindOneCommentResponse; | ||
import com.unit.daybook.domain.comment.entity.Comment; | ||
|
||
public interface CommentRepositoryCustom { | ||
List<Comment> findCommentByBoard(Long boardId); | ||
} |
18 changes: 16 additions & 2 deletions
18
src/main/java/com/unit/daybook/domain/comment/repository/CommentRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
package com.unit.daybook.domain.comment.repository; | ||
|
||
import static com.unit.daybook.domain.board.entity.QBoard.*; | ||
import static com.unit.daybook.domain.comment.entity.QComment.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.unit.daybook.domain.comment.entity.Comment; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CommentRepositoryImpl { | ||
public class CommentRepositoryImpl implements CommentRepositoryCustom{ | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
|
||
@Override | ||
public List<Comment> findCommentByBoard(Long boardId) { | ||
return jpaQueryFactory.selectFrom(comment) | ||
.leftJoin(comment.board, board) | ||
.fetchJoin() | ||
.where(board.boardId.eq(boardId)) | ||
.orderBy(comment.createdAt.desc()) | ||
.fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters