diff --git a/src/main/java/mvp/deplog/domain/comment/application/CommentService.java b/src/main/java/mvp/deplog/domain/comment/application/CommentService.java index c5947ee..d5d1576 100644 --- a/src/main/java/mvp/deplog/domain/comment/application/CommentService.java +++ b/src/main/java/mvp/deplog/domain/comment/application/CommentService.java @@ -6,6 +6,8 @@ import mvp.deplog.domain.comment.dto.request.CreateCommentReq; import mvp.deplog.domain.comment.dto.response.CommentListRes; import mvp.deplog.domain.comment.dto.response.ReplyListRes; +import mvp.deplog.domain.member.domain.Member; +import mvp.deplog.domain.member.dto.Avatar; import mvp.deplog.domain.post.domain.Post; import mvp.deplog.domain.post.domain.repository.PostRepository; import mvp.deplog.global.common.Message; @@ -32,10 +34,30 @@ public SuccessResponse> getCommentList(Long postId){ List commentDetails = new ArrayList<>(); for(Comment comment : commentList) { + Avatar avatar; + if (comment.isUseNickname()) { + avatar = Avatar.builder() + .avatarFace(null) + .avatarBody(null) + .avatarEyes(null) + .avatarNose(null) + .avatarMouth(null) + .build(); + } else { + Member member = comment.getMember(); + avatar = Avatar.builder() + .avatarFace(member.getAvatarFace()) + .avatarBody(member.getAvatarBody()) + .avatarEyes(member.getAvatarEyes()) + .avatarNose(member.getAvatarNose()) + .avatarMouth(member.getAvatarMouth()) + .build(); + } + if(comment.getParentComment() == null){ CommentListRes commentListRes = CommentListRes.builder() .commentId(comment.getId()) - .avatarImage(comment.getAvatarImage()) // 아바타 이미지 url + .avatar(avatar) .nickname(comment.getNickname()) .createdDate(comment.getCreatedDate().toLocalDate()) .content(comment.getContent()) @@ -47,7 +69,7 @@ public SuccessResponse> getCommentList(Long postId){ ReplyListRes replyListRes = ReplyListRes.builder() .commentId(comment.getId()) .parentCommentId(comment.getParentComment().getId()) - .avatarImage(comment.getAvatarImage()) // 아바타 이미지 url + .avatar(avatar) .nickname(comment.getNickname()) .createdDate(comment.getCreatedDate().toLocalDate()) .content(comment.getContent()) diff --git a/src/main/java/mvp/deplog/domain/comment/application/CreateMemberCommentServiceImpl.java b/src/main/java/mvp/deplog/domain/comment/application/CreateMemberCommentServiceImpl.java index 447032a..1781661 100644 --- a/src/main/java/mvp/deplog/domain/comment/application/CreateMemberCommentServiceImpl.java +++ b/src/main/java/mvp/deplog/domain/comment/application/CreateMemberCommentServiceImpl.java @@ -45,7 +45,7 @@ public SuccessResponse createComment(UserDetailsImpl userDetails, Creat .member(member) .content(createCommentReq.getContent()) .nickname(createCommentReq.getNickname()) - .avatarImage(createCommentReq.getAvatarImage()) + .useNickname(createCommentReq.isUseNicknameChecked()) .build(); commentRepository.save(comment); diff --git a/src/main/java/mvp/deplog/domain/comment/application/CreateMemberReplyServiceImpl.java b/src/main/java/mvp/deplog/domain/comment/application/CreateMemberReplyServiceImpl.java index 57e538c..af6c236 100644 --- a/src/main/java/mvp/deplog/domain/comment/application/CreateMemberReplyServiceImpl.java +++ b/src/main/java/mvp/deplog/domain/comment/application/CreateMemberReplyServiceImpl.java @@ -48,7 +48,7 @@ public SuccessResponse createComment(UserDetailsImpl userDetails, Creat .member(member) .content(createCommentReq.getContent()) .nickname(createCommentReq.getNickname()) - .avatarImage(createCommentReq.getAvatarImage()) + .useNickname(createCommentReq.isUseNicknameChecked()) .build(); commentRepository.save(reply); diff --git a/src/main/java/mvp/deplog/domain/comment/domain/Comment.java b/src/main/java/mvp/deplog/domain/comment/domain/Comment.java index 33aa333..2d86e38 100644 --- a/src/main/java/mvp/deplog/domain/comment/domain/Comment.java +++ b/src/main/java/mvp/deplog/domain/comment/domain/Comment.java @@ -38,21 +38,21 @@ public class Comment extends BaseEntity { @Column(name = "nickname") private String nickname; - @Column(name = "avatar_image", columnDefinition = "TEXT") - private String avatarImage; - @Column(name = "depth", columnDefinition = "INT", nullable = false) @Min(value = 1) private int depth; + @Column(name = "use_nickname", nullable = false) + private boolean useNickname; + @Builder(builderMethodName = "memberCommentBuilder", builderClassName = "MemberCommentBuilder") - public Comment(Post post, Member member, String content, String nickname, String avatarImage) { + public Comment(Post post, Member member, String content, String nickname, boolean useNickname) { this.parentComment = null; this.post = post; this.member = member; this.content = content; this.nickname = nickname; - this.avatarImage = avatarImage; + this.useNickname = useNickname; this.depth = 1; } @@ -63,18 +63,18 @@ public Comment(Post post, String content, String nickname) { this.member = null; this.content = content; this.nickname = nickname; - this.avatarImage = null; + this.useNickname = true; this.depth = 1; } @Builder(builderMethodName = "memberReplyBuilder", builderClassName = "MemberReplyBuilder") - public Comment(Comment parentComment, Post post, Member member, String content, String nickname, String avatarImage) { + public Comment(Comment parentComment, Post post, Member member, String content, String nickname, boolean useNickname) { this.parentComment = parentComment; this.post = post; this.member = member; this.content = content; this.nickname = nickname; - this.avatarImage = avatarImage; + this.useNickname = useNickname; this.depth = parentComment.getDepth() + 1; } @@ -85,7 +85,7 @@ public Comment(Comment parentComment, Post post, String content, String nickname this.member = null; this.content = content; this.nickname = nickname; - this.avatarImage = null; + this.useNickname = true; this.depth = parentComment.getDepth() + 1; } } diff --git a/src/main/java/mvp/deplog/domain/comment/dto/request/CreateCommentReq.java b/src/main/java/mvp/deplog/domain/comment/dto/request/CreateCommentReq.java index 8b6255d..9d4c25d 100644 --- a/src/main/java/mvp/deplog/domain/comment/dto/request/CreateCommentReq.java +++ b/src/main/java/mvp/deplog/domain/comment/dto/request/CreateCommentReq.java @@ -18,6 +18,6 @@ public class CreateCommentReq { @Schema(type = "String", example = "닉네임", description = "닉네임입니다.") private String nickname; - @Schema(type = "String", example = "www.avatarImage.png", description = "댓글 아바타 이미지 Url입니다. 비회원 혹은 닉네임 사용 미체크 시 null입니다.") - private String avatarImage; + @Schema(type = "boolean", example = "true", description = "닉네임 사용 체크박스 체크 여부입니다. 회원이 체크 안한 경우, 비회원의 경우 모두 true입니다. 회원이 누른 경우만 falseh입니다.") + private boolean useNicknameChecked; } diff --git a/src/main/java/mvp/deplog/domain/comment/dto/response/CommentListRes.java b/src/main/java/mvp/deplog/domain/comment/dto/response/CommentListRes.java index 79a2501..d83bbdb 100644 --- a/src/main/java/mvp/deplog/domain/comment/dto/response/CommentListRes.java +++ b/src/main/java/mvp/deplog/domain/comment/dto/response/CommentListRes.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Data; +import mvp.deplog.domain.member.dto.Avatar; import java.time.LocalDate; import java.util.List; @@ -16,8 +17,8 @@ public class CommentListRes { @Schema(type = "Long", example = "1", description = "댓글 아이디를 반환합니다.") private Long commentId; - @Schema(type = "String", example = "avatarImage.png", description = "댓글에 등록된 아바타 이미지를 반환합니다.") - private String avatarImage; + @Schema(type = "Avatar", description = "댓글 작성자의 아바타 이미지 객체입니다.") + private Avatar avatar; @Schema(type = "String", example = "댓글 작성자", description = "댓글 작성자의 닉네임을 반환합니다.") private String nickname; diff --git a/src/main/java/mvp/deplog/domain/comment/dto/response/ReplyListRes.java b/src/main/java/mvp/deplog/domain/comment/dto/response/ReplyListRes.java index ec63c70..bd3ace2 100644 --- a/src/main/java/mvp/deplog/domain/comment/dto/response/ReplyListRes.java +++ b/src/main/java/mvp/deplog/domain/comment/dto/response/ReplyListRes.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Data; +import mvp.deplog.domain.member.dto.Avatar; import java.time.LocalDate; @@ -11,22 +12,22 @@ @Builder public class ReplyListRes { - @Schema(type = "Long", example = "1", description = "댓글 아이디를 반환합니다.") + @Schema(type = "Long", example = "1", description = "대댓글 아이디를 반환합니다.") private Long commentId; @Schema(type = "Long", example = "1", description = "부모 댓글의 아이디를 반환합니다.") private Long parentCommentId; - @Schema(type = "String", example = "avatarImage.png", description = "대댓글에 등록된 아바타 이미지를 반환합니다.") - private String avatarImage; + @Schema(type = "Avatar", description = "대댓글 작성자의 아바타 이미지 객체입니다.") + private Avatar avatar; - @Schema(type = "String", example = "댓글 작성자", description = "댓글 작성자의 닉네임을 반환합니다.") + @Schema(type = "String", example = "대댓글 작성자", description = "대댓글 작성자의 닉네임을 반환합니다.") private String nickname; - @Schema(type = "localDate", example = "2024-08-01", description = "댓글 작성 날짜를 반환합니다.") + @Schema(type = "localDate", example = "2024-08-01", description = "대댓글 작성 날짜를 반환합니다.") @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING) private LocalDate createdDate; - @Schema(type = "String", example = "**댓글 내용**", description = "댓글 내용을 반환합니다.") + @Schema(type = "String", example = "**대댓글 내용**", description = "대댓글 내용을 반환합니다.") private String content; } diff --git a/src/main/resources/db/migration/V8__remove_comment_avatar.sql b/src/main/resources/db/migration/V8__remove_comment_avatar.sql new file mode 100644 index 0000000..b6eccfb --- /dev/null +++ b/src/main/resources/db/migration/V8__remove_comment_avatar.sql @@ -0,0 +1,5 @@ +ALTER TABLE comment + DROP COLUMN avatar_image; + +ALTER TABLE comment + ADD COLUMN use_nickname BOOLEAN NOT NULL; \ No newline at end of file