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
26 changes: 12 additions & 14 deletions src/main/java/org/websoso/WSSServer/domain/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.websoso.WSSServer.dto.feed.FeedCreateRequest;
import org.websoso.WSSServer.dto.feed.FeedUpdateRequest;

@Getter
@DynamicInsert
Expand Down Expand Up @@ -74,25 +72,25 @@ public class Feed {
@OneToOne(mappedBy = "feed", cascade = ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private PopularFeed popularFeed;

private Feed(FeedCreateRequest request, User user) {
this.feedContent = request.feedContent();
this.novelId = request.novelId();
this.isSpoiler = request.isSpoiler();
this.isPublic = request.isPublic();
private Feed(String feedContent, Long novelId, Boolean isSpoiler, Boolean isPublic, User user) {
this.feedContent = feedContent;
this.novelId = novelId;
this.isSpoiler = isSpoiler;
this.isPublic = isPublic;
this.user = user;
this.createdDate = LocalDateTime.now();
this.modifiedDate = this.createdDate;
}

public static Feed create(FeedCreateRequest request, User user) {
return new Feed(request, user);
public static Feed create(String feedContent, Long novelId, Boolean isSpoiler, Boolean isPublic, User user) {
return new Feed(feedContent, novelId, isSpoiler, isPublic, user);
}

public void updateFeed(FeedUpdateRequest request) {
this.feedContent = request.feedContent();
this.isSpoiler = request.isSpoiler();
this.isPublic = request.isPublic();
this.novelId = request.novelId();
public void updateFeed(String feedContent, Boolean isSpoiler, Boolean isPublic, Long novelId) {
this.feedContent = feedContent;
this.isSpoiler = isSpoiler;
this.isPublic = isPublic;
this.novelId = novelId;
this.modifiedDate = LocalDateTime.now();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public record FeedGetResponse(
List<String> relevantCategories,
Boolean isSpoiler,
Boolean isModified,
Boolean isMyFeed

Boolean isMyFeed,
Boolean isPublic
) {
public static FeedGetResponse of(Feed feed, UserBasicInfo userBasicInfo, Novel novel, Boolean isLiked,
List<String> relevantCategories, Boolean isMyFeed) {
Expand Down Expand Up @@ -60,7 +60,8 @@ public static FeedGetResponse of(Feed feed, UserBasicInfo userBasicInfo, Novel n
relevantCategories,
feed.getIsSpoiler(),
!feed.getCreatedDate().equals(feed.getModifiedDate()),
isMyFeed
isMyFeed,
feed.getIsPublic()
);
}

Expand All @@ -70,5 +71,4 @@ private static Float calculateNovelRating(Float novelRatingSum, Integer novelRat
}
return Math.round((novelRatingSum / (float) novelRatingCount) * 10) / 10.0f;
}

}
13 changes: 11 additions & 2 deletions src/main/java/org/websoso/WSSServer/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public class FeedService {
public void createFeed(User user, FeedCreateRequest request) {
Optional.ofNullable(request.novelId())
.ifPresent(novelService::getNovelOrException);
Feed feed = Feed.create(request, user);
Feed feed = Feed.create(
request.feedContent(),
request.novelId(),
request.isSpoiler(),
request.isPublic(),
user);
feedRepository.save(feed);
feedCategoryService.createFeedCategory(feed, request.relevantCategories());
}
Expand All @@ -94,7 +99,11 @@ public void updateFeed(Long feedId, FeedUpdateRequest request) {
if (request.novelId() != null && feed.isNovelChanged(request.novelId())) {
novelService.getNovelOrException(request.novelId());
}
feed.updateFeed(request);
feed.updateFeed(
request.feedContent(),
request.isSpoiler(),
request.isPublic(),
request.novelId());
feedCategoryService.updateFeedCategory(feed, request.relevantCategories());
}

Expand Down
Loading