Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.websoso.WSSServer.domain.Feed;
import org.websoso.WSSServer.domain.FeedImage;
import org.websoso.WSSServer.domain.Novel;
import org.websoso.WSSServer.domain.User;
import org.websoso.WSSServer.domain.UserNovel;
import org.websoso.WSSServer.dto.user.UserBasicInfo;

Expand All @@ -32,18 +31,18 @@ public record FeedGetResponse(
String novelThumbnailImage,
String novelGenre,
String novelAuthor,
Float userNovelRating,
Float feedWriterNovelRating,
String novelDescription
) {
public static FeedGetResponse of(Feed feed, UserBasicInfo feedUserBasicInfo, Novel novel, Boolean isLiked,
List<String> relevantCategories, Boolean isMyFeed, User user) {
List<String> relevantCategories, Boolean isMyFeed) {
String title = null;
Integer novelRatingCount = null;
Float novelRating = null;
String novelThumbnailImage = null;
String novelGenre = null;
String novelAuthor = null;
Float userNovelRating = null;
Float feedWriterNovelRating = null;
String novelDescription = null;

if (novel != null) {
Expand All @@ -60,7 +59,7 @@ public static FeedGetResponse of(Feed feed, UserBasicInfo feedUserBasicInfo, Nov
novelThumbnailImage = novel.getNovelImage();
novelGenre = novel.getNovelGenres().get(0).getGenre().getGenreName();
novelAuthor = novel.getAuthor();
userNovelRating = getUserNovelRating(novel, user.getUserId());
feedWriterNovelRating = getFeedWriterNovelRating(novel, feed.getUser().getUserId());
novelDescription = novel.getNovelDescription();
}

Expand Down Expand Up @@ -91,7 +90,7 @@ public static FeedGetResponse of(Feed feed, UserBasicInfo feedUserBasicInfo, Nov
novelThumbnailImage,
novelGenre,
novelAuthor,
userNovelRating,
feedWriterNovelRating,
novelDescription
);
}
Expand All @@ -103,14 +102,14 @@ private static Float calculateNovelRating(Float novelRatingSum, Integer novelRat
return Math.round((novelRatingSum / (float) novelRatingCount) * 10) / 10.0f;
}

private static Float getUserNovelRating(Novel novel, Long visitorId) {
private static Float getFeedWriterNovelRating(Novel novel, Long feedWriterId) {
if (novel == null) {
return null;
}

return novel.getUserNovels()
.stream()
.filter(userNovel -> userNovel.getUser().getUserId().equals(visitorId))
.filter(userNovel -> userNovel.getUser().getUserId().equals(feedWriterId))
.findFirst()
.map(UserNovel::getUserNovelRating)
.orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public FeedGetResponse getFeedById(User user, Long feedId) {
List<String> relevantCategories = feedCategoryService.getRelevantCategoryNames(feed.getFeedCategories());
Boolean isMyFeed = isUserFeedOwner(feed.getUser(), user);

return FeedGetResponse.of(feed, feedUserBasicInfo, novel, isLiked, relevantCategories, isMyFeed, user);
return FeedGetResponse.of(feed, feedUserBasicInfo, novel, isLiked, relevantCategories, isMyFeed);
}

@Transactional(readOnly = true)
Expand Down
Loading