Skip to content

Commit

Permalink
refactor: comment dto 분리 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonbinn committed Dec 15, 2023
1 parent 9e2dff1 commit 51bc02d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.api.TaveShot.domain.Comment.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
public class CommentCreateRequest {
private final String comment;
private final String memberId;
private final Long postId;
private final Long parentCommentId;
}
74 changes: 0 additions & 74 deletions src/main/java/com/api/TaveShot/domain/Comment/dto/CommentDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.api.TaveShot.domain.Comment.dto;

import com.api.TaveShot.domain.Comment.domain.Comment;
import com.querydsl.core.annotations.QueryProjection;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

@Getter
public class CommentResponse {
private final Long id;
private final String comment;
private final String memberId;
private final Long postId;
private final CommentResponse parentComment;
private final List<CommentResponse> replies;

@QueryProjection
public CommentResponse(Long id, String comment, String memberId, Long postId, CommentResponse parentComment, List<CommentResponse> replies) {
this.id = id;
this.comment = comment;
this.memberId = memberId;
this.postId = postId;
this.parentComment = parentComment;
this.replies = replies;
}

public static CommentResponse fromEntity(Comment commentEntity) {
List<CommentResponse> replies = commentEntity.getChildComments().stream()
.map(CommentResponse::fromEntity)
.collect(Collectors.toList());

return new CommentResponse(
commentEntity.getId(),
commentEntity.getComment(),
commentEntity.getMember().getGitName(),
commentEntity.getPost().getId(),
commentEntity.getParentComment() != null ? fromEntity(commentEntity.getParentComment()) : null,
replies
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.api.TaveShot.domain.Comment.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
public class CommentUpdateRequest {
private final String comment;
}

0 comments on commit 51bc02d

Please sign in to comment.