diff --git a/be/issue-tracker/src/main/java/com/issuetracker/comment/domain/Comment.java b/be/issue-tracker/src/main/java/com/issuetracker/comment/entity/Comment.java similarity index 85% rename from be/issue-tracker/src/main/java/com/issuetracker/comment/domain/Comment.java rename to be/issue-tracker/src/main/java/com/issuetracker/comment/entity/Comment.java index 8648b058b..44d1b2e43 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/comment/domain/Comment.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/comment/entity/Comment.java @@ -1,16 +1,14 @@ -package com.issuetracker.comment.domain; +package com.issuetracker.comment.entity; import java.time.LocalDateTime; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.Setter; import org.springframework.data.annotation.Id; @RequiredArgsConstructor @Getter public class Comment { @Id - @Setter private Long id; private final String content; private final LocalDateTime createDate; diff --git a/be/issue-tracker/src/main/java/com/issuetracker/comment/repository/CommentRepository.java b/be/issue-tracker/src/main/java/com/issuetracker/comment/repository/CommentRepository.java index dcb933010..9810e8c15 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/comment/repository/CommentRepository.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/comment/repository/CommentRepository.java @@ -1,6 +1,6 @@ package com.issuetracker.comment.repository; -import com.issuetracker.comment.domain.Comment; +import com.issuetracker.comment.entity.Comment; import java.util.List; import org.springframework.data.repository.CrudRepository; diff --git a/be/issue-tracker/src/main/java/com/issuetracker/comment/service/CommentService.java b/be/issue-tracker/src/main/java/com/issuetracker/comment/service/CommentService.java index 5f393bc25..d7ea4ab0e 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/comment/service/CommentService.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/comment/service/CommentService.java @@ -1,7 +1,14 @@ package com.issuetracker.comment.service; -import com.issuetracker.comment.domain.Comment; +import com.issuetracker.comment.dto.CommentDetailDto; +import com.issuetracker.comment.entity.Comment; import com.issuetracker.comment.repository.CommentRepository; +import com.issuetracker.comment.util.CommentMapper; +import com.issuetracker.file.dto.UploadedFileDto; +import com.issuetracker.file.service.FileService; +import com.issuetracker.member.dto.SimpleMemberDto; +import com.issuetracker.member.service.MemberService; +import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -11,9 +18,31 @@ @RequiredArgsConstructor @Slf4j public class CommentService { + private final MemberService memberService; private final CommentRepository commentRepository; + private final FileService fileService; - public List findCommentsById(Long id) { - return commentRepository.findAllByIssueId(id); + public List getCommentDetails(Long id) { + List comments = commentRepository.findAllByIssueId(id); + return toCommentDetails(comments); + } + + private List toCommentDetails(List comments) { + List commentDetails = new ArrayList<>(); + for (Comment comment : comments) { + SimpleMemberDto writer = memberService.getSimpleMemberById(comment.getMemberId()); + UploadedFileDto file = getFileByComment(comment); + CommentDetailDto commentDetail = CommentMapper.toCommentDetailDto(comment, writer, file); + commentDetails.add(commentDetail); + } + return commentDetails; + } + + private UploadedFileDto getFileByComment(Comment comment) { + Long fileId = comment.getFileId(); + if (fileId == null) { + return null; + } + return fileService.showFile(fileId); } } diff --git a/be/issue-tracker/src/main/java/com/issuetracker/comment/util/CommentMapper.java b/be/issue-tracker/src/main/java/com/issuetracker/comment/util/CommentMapper.java new file mode 100644 index 000000000..0b25f1312 --- /dev/null +++ b/be/issue-tracker/src/main/java/com/issuetracker/comment/util/CommentMapper.java @@ -0,0 +1,19 @@ +package com.issuetracker.comment.util; + +import com.issuetracker.comment.dto.CommentDetailDto; +import com.issuetracker.comment.entity.Comment; +import com.issuetracker.file.dto.UploadedFileDto; +import com.issuetracker.member.dto.SimpleMemberDto; + +public class CommentMapper { + public static CommentDetailDto toCommentDetailDto(Comment comment, SimpleMemberDto writer, UploadedFileDto file) { + return CommentDetailDto.builder() + .id(comment.getId()) + .content(comment.getContent()) + .writer(writer) + .isWriter(comment.isWriter()) + .file(file) + .createDate(comment.getCreateDate()) + .build(); + } +} diff --git a/be/issue-tracker/src/main/java/com/issuetracker/issue/service/IssueDetailService.java b/be/issue-tracker/src/main/java/com/issuetracker/issue/service/IssueDetailService.java index 5f96db306..b148f0bb6 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/issue/service/IssueDetailService.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/issue/service/IssueDetailService.java @@ -1,6 +1,5 @@ package com.issuetracker.issue.service; -import com.issuetracker.comment.domain.Comment; import com.issuetracker.comment.dto.CommentDetailDto; import com.issuetracker.comment.service.CommentService; import com.issuetracker.file.dto.UploadedFileDto; @@ -14,7 +13,6 @@ import com.issuetracker.member.service.MemberService; import com.issuetracker.milestone.dto.SimpleMilestoneDto; import com.issuetracker.milestone.service.MilestoneService; -import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -43,7 +41,7 @@ public IssueDetailDto showIssue(Long id) { UploadedFileDto file = getFileByIssue(issue); List