-
Notifications
You must be signed in to change notification settings - Fork 5
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
12 changed files
with
181 additions
and
39 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
39 changes: 39 additions & 0 deletions
39
server/src/main/java/com/main36/pikcha/domain/comment/dto/CommentDetailResponseDto.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,39 @@ | ||
package com.main36.pikcha.domain.comment.dto; | ||
|
||
import com.main36.pikcha.domain.comment.entity.Comment; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class CommentDetailResponseDto { | ||
private Long commentId; | ||
private Long parentId; | ||
private Long memberId; | ||
private String username; | ||
private String memberPicture; | ||
private String commentContent; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime modifiedAt; | ||
private List<CommentDetailResponseDto> children; | ||
|
||
public static CommentDetailResponseDto convertCommentToDto(Comment comment){ | ||
return CommentDetailResponseDto.builder() | ||
.commentId(comment.getCommentId()) | ||
.parentId(comment.getParent() == null ? null : comment.getParent().getCommentId()) | ||
.memberId(comment.getMember().getMemberId()) | ||
.username(comment.getMember().getUsername()) | ||
.memberPicture(comment.getMember().getPicture()) | ||
.commentContent(comment.getCommentContent()) | ||
.createdAt(comment.getCreatedAt()) | ||
.modifiedAt(comment.getModifiedAt()) | ||
.children(new ArrayList<>()) | ||
.build(); | ||
} | ||
} |
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
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
53 changes: 53 additions & 0 deletions
53
...rc/main/java/com/main36/pikcha/domain/comment/repository/CommentCustomRepositoryImpl.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,53 @@ | ||
package com.main36.pikcha.domain.comment.repository; | ||
|
||
import com.main36.pikcha.domain.comment.entity.Comment; | ||
import com.main36.pikcha.domain.post.entity.Post; | ||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.main36.pikcha.domain.comment.entity.QComment.comment; | ||
|
||
@Repository | ||
public class CommentCustomRepositoryImpl implements CommentCustomRepository{ | ||
private JPAQueryFactory jpaQueryFactory; | ||
|
||
public CommentCustomRepositoryImpl(JPAQueryFactory jpaQueryFactory) { | ||
this.jpaQueryFactory = jpaQueryFactory; | ||
} | ||
|
||
@Override | ||
public Page<Comment> findCommentByPost(Post post, Pageable pageable) { | ||
List<Comment> commentList = findCommnetList(post, pageable); | ||
|
||
JPAQuery<Long> countQuery = getCount(post); | ||
|
||
return PageableExecutionUtils.getPage(commentList, pageable, ()-> countQuery.fetchOne()); | ||
} | ||
|
||
private JPAQuery<Long> getCount(Post post) { | ||
JPAQuery<Long> countQuery = jpaQueryFactory | ||
.select(comment.count()) | ||
.from(comment) | ||
.where(comment.post.postId.eq(post.getPostId())); | ||
|
||
return countQuery; | ||
} | ||
|
||
private List<Comment> findCommnetList(Post post, Pageable pageable){ | ||
return jpaQueryFactory.selectFrom(comment) | ||
.leftJoin(comment.parent) | ||
.fetchJoin() | ||
.where(comment.post.postId.eq(post.getPostId())) | ||
.orderBy(comment.parent.commentId.asc().nullsFirst(), comment.createdAt.asc()) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
spring: | ||
profiles: | ||
active: server | ||
active: local |