Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOTFIX] NovelStatisticsService에서 NovelService 참조 로직 제거 #63

Merged
merged 1 commit into from
Jun 10, 2024
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 @@ -2,18 +2,13 @@

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.websoso.WSSServer.domain.Novel;
import org.websoso.WSSServer.domain.NovelStatistics;

@Repository
public interface NovelStatisticsRepository extends JpaRepository<NovelStatistics, Long> {

@Query("SELECT ns FROM NovelStatistics ns WHERE ns.novel.novelId = :novelId")
Optional<NovelStatistics> findByNovelId(@Param("novelId") Long novelId);


Optional<NovelStatistics> findByNovel(Novel novel);

}
5 changes: 3 additions & 2 deletions src/main/java/org/websoso/WSSServer/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FeedService {
private final FeedRepository feedRepository;
private final CategoryService categoryService;
private final NovelStatisticsService novelStatisticsService;
private final NovelService novelService;

@Transactional
public void createFeed(User user, FeedCreateRequest request) {
Expand All @@ -34,7 +35,7 @@ public void createFeed(User user, FeedCreateRequest request) {
.build();

if (request.novelId() != null) {
novelStatisticsService.increaseNovelFeedCount(request.novelId());
novelStatisticsService.increaseNovelFeedCount(novelService.getNovelOrException(request.novelId()));
}

feedRepository.save(feed);
Expand All @@ -58,7 +59,7 @@ public void deleteFeed(User user, Long feedId) {
feed.validateUserAuthorization(user, DELETE);

if (feed.getNovelId() != null) {
novelStatisticsService.decreaseNovelFeedCount(feed.getNovelId());
novelStatisticsService.decreaseNovelFeedCount(novelService.getNovelOrException(feed.getNovelId()));
}

feedRepository.delete(feed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
public class NovelStatisticsService {

private final NovelStatisticsRepository novelStatisticsRepository;
private final NovelService novelService;

@Transactional
public void increaseNovelFeedCount(Long novelId) {
NovelStatistics novelStatistics = novelStatisticsRepository.findByNovelId(novelId)
.orElseGet(() -> createNovelStatistics(novelId));
public void increaseNovelFeedCount(Novel novel) {
NovelStatistics novelStatistics = novelStatisticsRepository.findByNovel(novel)
.orElseGet(() -> createNovelStatistics(novel));

novelStatistics.increaseNovelFeedCount();
}

@Transactional
public NovelStatistics createNovelStatistics(Long novelId) {
Novel novel = novelService.getNovelOrException(novelId);

public NovelStatistics createNovelStatistics(Novel novel) {
return novelStatisticsRepository.save(
NovelStatistics.builder()
.novel(novel)
Expand All @@ -37,10 +34,8 @@ public NovelStatistics createNovelStatistics(Long novelId) {
}

@Transactional
public void decreaseNovelFeedCount(Long novelId) {
NovelStatistics novelStatistics = novelStatisticsRepository.findByNovelId(novelId)
.orElseThrow(() -> new InvalidNovelStatisticsException(NOVEL_STATISTICS_NOT_FOUND,
"novel statistics not found"));
public void decreaseNovelFeedCount(Novel novel) {
NovelStatistics novelStatistics = getNovelStatisticsOrException(novel);

novelStatistics.decreaseNovelFeedCount();
}
Expand Down
Loading