diff --git a/src/main/java/com/pickple/server/api/comment/dto/response/CommentGetResponse.java b/src/main/java/com/pickple/server/api/comment/dto/response/CommentGetResponse.java index 5ce0bc7..5d1f9b7 100644 --- a/src/main/java/com/pickple/server/api/comment/dto/response/CommentGetResponse.java +++ b/src/main/java/com/pickple/server/api/comment/dto/response/CommentGetResponse.java @@ -15,6 +15,9 @@ public record CommentGetResponse( String commentContent, - String commentDate + String commentDate, + + boolean isVeteran + ) { } diff --git a/src/main/java/com/pickple/server/api/comment/service/CommentQueryService.java b/src/main/java/com/pickple/server/api/comment/service/CommentQueryService.java index 049bc86..9f31fdc 100644 --- a/src/main/java/com/pickple/server/api/comment/service/CommentQueryService.java +++ b/src/main/java/com/pickple/server/api/comment/service/CommentQueryService.java @@ -8,6 +8,8 @@ import com.pickple.server.api.guest.repository.GuestRepository; import com.pickple.server.api.host.domain.Host; import com.pickple.server.api.host.repository.HostRepository; +import com.pickple.server.api.moim.domain.enums.MoimState; +import com.pickple.server.api.moim.repository.MoimRepository; import com.pickple.server.api.notice.domain.Notice; import com.pickple.server.api.notice.repository.NoticeRepository; import java.time.format.DateTimeFormatter; @@ -21,10 +23,12 @@ @RequiredArgsConstructor @Transactional(readOnly = true) public class CommentQueryService { + private final NoticeRepository noticeRepository; private final CommentRepository commentRepository; private final HostRepository hostRepository; private final GuestRepository guestRepository; + private final MoimRepository moimRepository; public List getCommentListByNotice(Long noticeId) { Notice notice = noticeRepository.findNoticeByIdOrThrow(noticeId); @@ -44,6 +48,8 @@ public List getCommentListByNotice(Long noticeId) { .commenterNickname(commenterInfo.getProfileNickname()) .commentContent(comment.getCommentContent()) .commentDate(comment.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss"))) + .isVeteran(checkVeteran(isOwner, + hostRepository.findHostByUserId(comment.getCommenter().getId()).getId())) .build(); }).collect(Collectors.toList()); } @@ -62,4 +68,12 @@ public boolean checkOwner(Long userId, Long noticeId) { Notice notice = noticeRepository.findNoticeByIdOrThrow(noticeId); return notice.getMoim().getHost().getUser().getId().equals(userId); } + + private boolean checkVeteran(boolean isOwner, Long hostId) { + if (isOwner) { + int count = moimRepository.countByHostIdAndMoimState(hostId, MoimState.COMPLETED.getMoimState()); + return count >= 2; + } + return false; + } }