Skip to content

Commit

Permalink
#3 feat: 댓글 작성자 세부 분류-질문자 쥬니, 답변자 시니, 익명의 시니, 익명의 쥬니
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim committed Jan 14, 2024
1 parent 06a4895 commit 12d12a8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.ewhatever.qna.common.Base.BaseException;
import com.ewhatever.qna.common.Base.BaseResponse;
import com.ewhatever.qna.login.JwtIssuer;
import com.ewhatever.qna.post.dto.GetPostRes;
import com.ewhatever.qna.post.dto.GetPostsRes;
import com.ewhatever.qna.post.service.PostService;
Expand All @@ -20,7 +19,6 @@
public class PostController {
private final PostService postService;


/**
* [GET] 쥬시글 목록 조회
*/
Expand Down
46 changes: 40 additions & 6 deletions src/main/java/com/ewhatever/qna/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -185,11 +186,10 @@ private List<GetPostRes.CommentDto> getCommentList(Post post, User user) {
for (Comment comment : comments) {
GetPostRes.CommentDto commentDto = new GetPostRes.CommentDto(
comment.getCommentIdx(),
getWriter(comment.getWriter().getRole().name()),
getWriter(post, comment.getWriter()),
comment.getCreatedDate(),
comment.getContent(),
isWriter(user, comment)
);
isWriter(user, comment));
commentList.add(commentDto);
}
return commentList;
Expand All @@ -200,10 +200,44 @@ private Boolean isWriter(User user, Comment comment) {
return comment.getWriter().equals(user);
}

// 댓글 작성자를 담을 리스트
private HashMap<User, Integer> cyniIndexMap = new HashMap<>();
private ArrayList<User> cyniCommentWriterList = new ArrayList<>();
private HashMap<User, Integer> juniIndexMap = new HashMap<>();
private ArrayList<User> juniCommetWriterList = new ArrayList<>();

// 댓글 작성자
private String getWriter(String role) {
if (role.equals(Role.Cyni.name())) return "익명의 시니";
else return "익명의 쥬니";
private String getWriter(Post post, User commentWriter) {
List<Answer> answerList = answerRepository.findAllByPostOrderByCreatedDateDesc(post);

boolean isAnswerer = false;
for (Answer answer : answerList) {
if (commentWriter.equals(answer.getAnswerer())) {
isAnswerer = true;
break;
}
}

if (commentWriter.equals(post.getQuestioner())) return "질문자 쥬니";
else if (isAnswerer) return "답변자 시니";
else {
if (commentWriter.equals(Role.Cyni.name())) {
if (!cyniCommentWriterList.contains(commentWriter)) {
cyniCommentWriterList.add(commentWriter);
}
int index = cyniCommentWriterList.indexOf(commentWriter) + 1;
cyniIndexMap.put(commentWriter, index);
return "익명의 시니" + index;
}
else {
if (!juniCommetWriterList.contains(commentWriter)) {
juniCommetWriterList.add(commentWriter);
}
int index = juniCommetWriterList.indexOf(commentWriter) + 1;
juniIndexMap.put(commentWriter, index);
return "익명의 쥬니" + index;
}
}
}

/**
Expand Down

0 comments on commit 12d12a8

Please sign in to comment.