Skip to content

Commit

Permalink
[FEAT] 익명댓글 기능 추가 (#186)
Browse files Browse the repository at this point in the history
Co-authored-by: bellmin <[email protected]>
  • Loading branch information
Daae-Kim and bellmin authored Dec 1, 2024
1 parent ed73c36 commit 0dc45fb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blackcompany.eeos.comment.application.dto;

import com.blackcompany.eeos.comment.application.model.CommentType;
import com.blackcompany.eeos.common.support.dto.AbstractRequestDto;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand All @@ -17,4 +18,5 @@ public class CreateCommentRequest implements AbstractRequestDto {
private @NotNull Long teamId;
private @NotNull Long parentsCommentId;
private @NotNull String content;
private @NotNull CommentType commentType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.blackcompany.eeos.comment.application.dto.QueryCommentsResponse;
import com.blackcompany.eeos.comment.application.exception.NotConvertedCommentException;
import com.blackcompany.eeos.comment.application.model.CommentModel;
import com.blackcompany.eeos.comment.application.model.CommentType;
import com.blackcompany.eeos.member.application.exception.NotFoundMemberException;
import com.blackcompany.eeos.member.persistence.MemberRepository;
import java.time.format.DateTimeFormatter;
Expand All @@ -19,6 +20,7 @@
public class CommentResponseConverter {

private final MemberRepository memberRepository;
private final String ANONYMOUS_USER_NAME = "익명";

public CommandCommentResponse from(CommentModel source) {
return CommandCommentResponse.builder().commentId(source.getId()).build();
Expand All @@ -38,7 +40,7 @@ public QueryCommentResponse from(Long memberId, CommentModel source, List<Commen
.time(getCreateTimeString(source))
.content(source.getContent())
.teamId(source.getPresentingTeam())
.writer(findMemberName(source.getWriter()))
.writer(findMemberName(source.getWriter(), source))
.commentId(source.getId())
.accessRight(source.getAccessRight(memberId))
.answers(answersResponse)
Expand All @@ -51,14 +53,19 @@ private QueryAnswerResponse from(CommentModel source, Long memberId) {
QueryAnswerResponse.builder()
.commentId(source.getId())
.content(source.getContent())
.writer(findMemberName(source.getWriter()))
.writer(findMemberName(source.getWriter(), source))
.time(getCreateTimeString(source))
.accessRight(source.getAccessRight(memberId))
.build();
return response;
}

private String findMemberName(Long memberId) {
private String findMemberName(Long memberId, CommentModel source) {
System.out.println("writer : " + source.getWriter());
System.out.println("check : " + source.getCommentType());
if (source.getCommentType().equals(CommentType.ANONYMOUS)) {
return ANONYMOUS_USER_NAME;
}
return memberRepository.findById(memberId).orElseThrow(NotFoundMemberException::new).getName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CommentModel implements AbstractModel {
private Timestamp updatedDate;
private String content;
private Long writer;
private CommentType commentType;

public String getAccessRight(Long memberId) {
if (isEdit(memberId)) return AccessRights.EDIT.getAccessRight();
Expand Down Expand Up @@ -59,7 +60,7 @@ private boolean isEdit(Long memberId) {
}

private boolean isExceedLengthLimit() {
return getContentLength() > contentLimitLength;
return false; // 코멘트 길이 수는 제한이 없다
}

private long getContentLength() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.blackcompany.eeos.comment.application.model;

public enum CommentType {
ANONYMOUS,
NON_ANONYMOUS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ public CommentModel from(CreateCommentRequest request) {
.superCommentId(request.getParentsCommentId())
.content(request.getContent())
.presentingTeam(request.getTeamId())
.commentType(request.getCommentType())
.build();
}

/*public CommentModel from(Long memberId,CreateCommentRequest request){
CommentModel model = from(request);
if(Boolean.TRUE.equals(model.getIsChecked())){
return model.toBuilder().writer(-1L).build();
}else{
return model.toBuilder().writer(memberId).build();
}
}*/

public CommentModel from(Long memberId, CreateCommentRequest request) {
return from(request).toBuilder().writer(memberId).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.blackcompany.eeos.comment.persistence;

import com.blackcompany.eeos.comment.application.model.CommentType;
import com.blackcompany.eeos.common.persistence.BaseEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand Down Expand Up @@ -48,4 +51,8 @@ public class CommentEntity extends BaseEntity {

@Column(name = ENTITY_PREFIX + "_super_comment_id", nullable = false)
private Long superCommentId;

@Column(name = ENTITY_PREFIX + "_commentType", nullable = false)
@Enumerated(EnumType.STRING)
private CommentType commentType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public CommentEntity toEntity(CommentModel model) {
.writer(model.getWriter())
.presentingTeamId(model.getPresentingTeam())
.content(model.getContent())
.commentType(model.getCommentType())
.build();
}

@Override
public CommentModel from(CommentEntity entity) {

return CommentModel.builder()
.id(entity.getId())
.programId(entity.getProgramId())
Expand All @@ -31,6 +33,7 @@ public CommentModel from(CommentEntity entity) {
.updatedDate(entity.getUpdatedDate())
.content(entity.getContent())
.superCommentId(entity.getSuperCommentId())
.commentType(entity.getCommentType())
.build();
}
}

0 comments on commit 0dc45fb

Please sign in to comment.