Skip to content

Commit

Permalink
Merge pull request #98 from DEPthes/refactor/#95-comment-avatar
Browse files Browse the repository at this point in the history
[REFACTOR]: 댓글 조회 시 체크박스 여부에 따른 아바타 이미지 관련 로직 수정
  • Loading branch information
phonil authored Aug 17, 2024
2 parents d948fa9 + c7153e3 commit a04a571
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,10 +34,30 @@ public SuccessResponse<List<CommentListRes>> getCommentList(Long postId){
List<CommentListRes> 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())
Expand All @@ -47,7 +69,7 @@ public SuccessResponse<List<CommentListRes>> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SuccessResponse<Message> createComment(UserDetailsImpl userDetails, Creat
.member(member)
.content(createCommentReq.getContent())
.nickname(createCommentReq.getNickname())
.avatarImage(createCommentReq.getAvatarImage())
.useNickname(createCommentReq.isUseNicknameChecked())
.build();

commentRepository.save(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SuccessResponse<Message> createComment(UserDetailsImpl userDetails, Creat
.member(member)
.content(createCommentReq.getContent())
.nickname(createCommentReq.getNickname())
.avatarImage(createCommentReq.getAvatarImage())
.useNickname(createCommentReq.isUseNicknameChecked())
.build();

commentRepository.save(reply);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/mvp/deplog/domain/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
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;

@Data
@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;
}
5 changes: 5 additions & 0 deletions src/main/resources/db/migration/V8__remove_comment_avatar.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE comment
DROP COLUMN avatar_image;

ALTER TABLE comment
ADD COLUMN use_nickname BOOLEAN NOT NULL;

0 comments on commit a04a571

Please sign in to comment.