Open berryberrybin opened 1 year ago
처음 해결하고자 했던 방안
private boolean authorIsOwner
필드에 사장님인지 여부를 판단해서 값을 세팅함.getClass().getSimpleName()
에서 반환 값이 Owner일 경우 AuthorIsOwner
값을 true로 지정함발생한 문제점
.getClass().getSimpleName()
이 제대로 나오지 않음 public Slice<CommentInfo> RetrieveCommentListByFeedId(CommentQuery.RetrieveCommentListByFeedId query) {
UUID loginUserId = query.getLoginUserId();
findUserById(loginUserId);
UUID feedId = query.getFeedId();
Feed feed = findFeedById(feedId);
Slice<CommentInfo> commentInfos = commentRepository.findAllByFeedIdAndParentCommentIsNull(feedId, query.getPageable())
.map(comment -> CommentInfoMapper.INSTANCE.of(comment))
.map(commentInfo -> putCommentInfoExtra(commentInfo, loginUserId));
return commentInfos;
}
private CommentInfo putCommentInfoExtra(CommentInfo commentInfo, UUID loginUserId){
commentInfo.setViewerHasLiked(commentLikeRepository.existsByUserIdAndCommentId(loginUserId, commentInfo.getCommentId()));
userRepository.getReferenceById(commentInfo.getCommentId());
// 추가한 코드
if(findUserById(commentInfo.getAuthorId()).getClass().getSimpleName().equals("Owner")){
commentInfo.setAuthorIsOwner(true);
}
if(commentInfo.getChildComments() != null ){
for(CommentInfo childCommentInfo : commentInfo.getChildComments()){
putCommentInfoExtra(childCommentInfo, loginUserId);
}
}
return commentInfo;
}
private User findUserById(UUID userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "user.byId", List.of(userId.toString())));
}
구현 내용 및 고려사항
해결 방법
@DiscriminatorColumn
을 선언하여DTYPE
이름의 하위 테이블 구분 컬럼을 생성하고 있음읽기 전용
으로 다음 같이 선언함실제 코드