Skip to content

Commit

Permalink
[�merge] 댓글 관련 베테랑 스티커를 위한 response 추가
Browse files Browse the repository at this point in the history
[feat] 댓글 관련 베테랑 스티커를 위한 response 추가
  • Loading branch information
bo-ram-bo-ram authored Sep 18, 2024
2 parents fbe5058 + 91d86ab commit 6ee5653
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public record CommentGetResponse(

String commentContent,

String commentDate
String commentDate,

boolean isVeteran

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CommentGetResponse> getCommentListByNotice(Long noticeId) {
Notice notice = noticeRepository.findNoticeByIdOrThrow(noticeId);
Expand All @@ -44,6 +48,8 @@ public List<CommentGetResponse> 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());
}
Expand All @@ -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;
}
}

0 comments on commit 6ee5653

Please sign in to comment.