Skip to content

Commit

Permalink
REFACTOR(comment) :: commentDto record로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Woongbin06 committed Oct 13, 2024
1 parent 529e5f7 commit 15c810a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean isWriter(Long writerId) {
}

public void update(CreateCommentRequest request) {
this.content = request.getContent();
this.content = request.content();
}

public void increaseReCommentCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public boolean isWriter(Long id) {
}

public void update(CreateCommentRequest request) {
this.content = request.getContent();
this.content = request.content();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.woongeya.zoing.domain.comment.presetation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.woongeya.zoing.domain.comment.domain.Comment;
import com.woongeya.zoing.domain.user.domain.User;

import jakarta.validation.constraints.NotNull;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CreateCommentRequest {

public record CreateCommentRequest (
@NotNull
private String content;
String content
) {

public Comment toEntity(Long postId, User user) {
return new Comment(content, postId, user.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.woongeya.zoing.domain.comment.presetation.dto.response;

import java.time.LocalDateTime;

import com.woongeya.zoing.domain.comment.domain.Comment;
import com.woongeya.zoing.domain.user.domain.User;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import lombok.Builder;

@Getter
@Builder
public class CommentResponse {

private Long id;
private String content;
private LocalDateTime createTime;
private Long userId;
private String userNickName;
private String userImg;
private Integer reCommentCount;

public record CommentResponse (
Long id,
String content,
LocalDateTime createTime,
Long userId,
String userNickName,
String userImg,
Integer reCommentCount
) {
public static CommentResponse of(Comment comment, User user) {
return CommentResponse.builder()
.id(comment.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@

import java.time.LocalDateTime;

@Getter
@Builder
public class ReCommentResponse {

private Long id;
private String content;
private LocalDateTime createTime;
private Long userId;
private String userNickName;
private String userImg;

public record ReCommentResponse (
Long id,
String content,
LocalDateTime createTime,
Long userId,
String userNickName,
String userImg
) {
public static ReCommentResponse of(ReComment reComment, User user) {
return ReCommentResponse.builder()
.id(reComment.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute(Long postId, CreateCommentRequest request) {
User user = userFacade.getCurrentUser();
Post post = postRepository.findById(postId)
.orElseThrow(() -> PostNotFoundException.EXCEPTION);
commentRepository.save(new Comment(request.getContent(), postId, user.getId()));
commentRepository.save(request.toEntity(postId, user));
post.increaseCommentCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void execute(Long id, CreateCommentRequest request) {
Comment comment = commentRepository.findById(id)
.orElseThrow(() -> CommentNotFoundException.EXCEPTION);
reCommentRepository.save(
new ReComment(request.getContent(), id, user.getId())
new ReComment(request.content(), id, user.getId())
);
comment.increaseReCommentCount();
}
Expand Down

0 comments on commit 15c810a

Please sign in to comment.