Skip to content

Commit

Permalink
refactor: new로 생성자 제거, Builder 패턴으로 변경 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonbinn committed Dec 30, 2023
1 parent f42f78b commit 13378cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ public static CommentResponse entityToDto(final Comment commentEntity) {
.map(CommentConverter::entityToDto)
.toList();

return new CommentResponse(
commentEntity.getId(),
commentEntity.getContent(),
commentEntity.getMember().getGitLoginId(),
commentEntity.getPost().getId(),
commentEntity.getParent(),
replies);
CommentResponse parentResponse = getParentResponse(commentEntity);

return CommentResponse.builder()
.id(commentEntity.getId())
.content(commentEntity.getContent())
.memberId(commentEntity.getMember().getGitLoginId())
.postId(commentEntity.getPost().getId())
.parent(parentResponse)
.replies(replies)
.build();
}

public static CommentResponse getParentCommentResponse(Comment commentEntity) {
public static CommentResponse getParentResponse(Comment commentEntity) {
if (commentEntity.getParent() != null) {
return entityToDto(commentEntity.getParent());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.api.TaveShot.domain.comment.converter.CommentConverter;
import com.api.TaveShot.domain.comment.domain.Comment;
import com.querydsl.core.annotations.QueryProjection;
import lombok.Builder;
import lombok.Getter;

import java.util.List;


@Getter
@Builder
public class CommentResponse {
private final Long id;
private final String content;
Expand All @@ -17,12 +20,13 @@ public class CommentResponse {
private final List<CommentResponse> replies;

@QueryProjection
@Builder
public CommentResponse(Long id, String content, String memberId, Long postId, Comment parent, List<CommentResponse> replies) {
this.id = id;
this.content = content;
this.memberId = memberId;
this.postId = postId;
this.parent = CommentConverter.getParentCommentResponse(parent);
this.parent = CommentConverter.getParentResponse(parent);
this.replies = replies;
}

Expand Down

0 comments on commit 13378cb

Please sign in to comment.