Skip to content

Commit

Permalink
[FIX] feed에 연결된 novel이 null일 때 발생하는 NPE 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-TaeUk committed Sep 17, 2024
1 parent 35f50da commit 95b0d0c
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static UserFeedGetResponse of(Feed feed, Novel novel, Long visitorId) {
isLiked,
feed.getLikes().size(),
feed.getComments().size(),
novel.getNovelId(),
novel.getTitle(),
novel == null ?
null : novel.getNovelId(),
novel == null ?
null : novel.getTitle(),
novelRating,
novelRatingCount,
relevantCategories
Expand All @@ -69,21 +71,31 @@ private static List<Long> getLikeUsers(Feed feed) {
}

private static Long getNovelRatingCount(Novel novel) {
if (novel == null) {
return null;
}
return novel.getUserNovels()
.stream()
.filter(userNovel -> userNovel.getUserNovelRating() != 0.0f)
.count();
}

private static Float getNovelRatingSum(Novel novel) {
if (novel == null) {
return null;
}

return (float) novel.getUserNovels()
.stream()
.filter(userNovel -> userNovel.getUserNovelRating() != 0.0f)
.mapToDouble(UserNovel::getUserNovelRating)
.sum();
}

private static float getNovelRating(Novel novel, Long novelRatingCount) {
private static Float getNovelRating(Novel novel, Long novelRatingCount) {
if (novel == null) {
return null;
}
return novelRatingCount > 0
? getNovelRatingSum(novel) / novelRatingCount
: 0.0f;
Expand Down

0 comments on commit 95b0d0c

Please sign in to comment.