Skip to content

Commit

Permalink
[MERGE] dev branch merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rinarina0429 committed Jun 24, 2024
2 parents 7ee7174 + 12301a0 commit 973c4d5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

@Service
@RequiredArgsConstructor
@Transactional
public class CategoryService {

private final CategoryRepository categoryRepository;

@Transactional
public void createCategory(Feed feed, List<String> relevantCategories) {
CategoryBuilder builder = Category.builder()
.feed(feed);
Expand All @@ -44,7 +44,6 @@ public void createCategory(Feed feed, List<String> relevantCategories) {
categoryRepository.save(category);
}

@Transactional
public void updateCategory(Feed feed, List<String> relevantCategories) {
Long categoryId = categoryRepository.findByFeed(feed).orElseThrow(() ->
new InvalidCategoryException(CATEGORY_NOT_FOUND, "Category for the given feed was not found"))
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/websoso/WSSServer/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

@Service
@RequiredArgsConstructor
@Transactional
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) {
Feed feed = Feed.builder()
.feedContent(request.feedContent())
Expand All @@ -42,7 +42,6 @@ public void createFeed(User user, FeedCreateRequest request) {
categoryService.createCategory(feed, request.relevantCategories());
}

@Transactional
public void updateFeed(User user, Long feedId, FeedUpdateRequest request) {
Feed feed = getFeedOrException(feedId);

Expand All @@ -61,7 +60,6 @@ public void updateFeed(User user, Long feedId, FeedUpdateRequest request) {
categoryService.updateCategory(feed, request.relevantCategories());
}

@Transactional
public void deleteFeed(User user, Long feedId) {
Feed feed = getFeedOrException(feedId);

Expand All @@ -74,7 +72,6 @@ public void deleteFeed(User user, Long feedId) {
feedRepository.delete(feed);
}

@Transactional
public void likeFeed(User user, Long feedId) {
Feed feed = getFeedOrException(feedId);

Expand All @@ -83,7 +80,6 @@ public void likeFeed(User user, Long feedId) {
feed.addLike(likeUserId);
}

@Transactional
public void unLikeFeed(User user, Long feedId) {
Feed feed = getFeedOrException(feedId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Transactional
public class KeywordService {

private final KeywordRepository keywordRepository;

@Transactional(readOnly = true)
public KeywordByCategoryGetResponse searchKeywordByCategory(String query) {
List<CategoryGetResponse> categories = Arrays.stream(KeywordCategory.values())
.map(category -> CategoryGetResponse.of(category, sortByCategory(category, searchKeyword(query))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Transactional
public class NoticeService {

private final NoticeRepository noticeRepository;
private static final Role ADMIN_ROLE = ADMIN;

@Transactional
public void createNotice(User user, NoticePostRequest noticePostRequest) {
validateAuthorization(user);
noticeRepository.save(Notice.builder()
Expand All @@ -36,7 +35,6 @@ public void createNotice(User user, NoticePostRequest noticePostRequest) {
.build());
}

@Transactional
public void editNotice(User user, Long noticeId, NoticeEditRequest noticeEditRequest) {
validateAuthorization(user);
Notice notice = getNoticeOrException(noticeId);
Expand All @@ -51,12 +49,12 @@ private static void validateAuthorization(User user) {
}
}

@Transactional(readOnly = true)
public NoticesGetResponse getNotices(User user) {
List<Notice> notices = noticeRepository.findByUserId(user.getUserId());
return NoticesGetResponse.of(notices);
}

@Transactional
public void deleteNotice(User user, Long noticeId) {
validateAuthorization(user);
Notice notice = getNoticeOrException(noticeId);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/websoso/WSSServer/service/NovelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.websoso.WSSServer.domain.Novel;
import org.websoso.WSSServer.domain.NovelGenre;
import org.websoso.WSSServer.domain.User;
Expand All @@ -16,12 +17,14 @@

@Service
@RequiredArgsConstructor
@Transactional
public class NovelService {

private final NovelRepository novelRepository;
private final NovelStatisticsService novelStatisticsService;
private final UserNovelService userNovelService;

@Transactional(readOnly = true)
public NovelGetResponse1 getNovelInfo1(User user, Long novelId) {
Novel novel = getNovelOrException(novelId);
List<NovelGenre> novelGenres = novel.getNovelGenres();
Expand All @@ -34,6 +37,7 @@ public NovelGetResponse1 getNovelInfo1(User user, Long novelId) {
);
}

@Transactional(readOnly = true)
public Novel getNovelOrException(Long novelId) {
return novelRepository.findById(novelId)
.orElseThrow(() -> new InvalidNovelException(NOVEL_NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@

@Service
@RequiredArgsConstructor
@Transactional
public class NovelStatisticsService {

private final NovelStatisticsRepository novelStatisticsRepository;

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

novelStatistics.increaseNovelFeedCount();
}

@Transactional
public NovelStatistics createNovelStatistics(Novel novel) {
return novelStatisticsRepository.save(
NovelStatistics.builder()
Expand All @@ -33,13 +32,13 @@ public NovelStatistics createNovelStatistics(Novel novel) {
);
}

@Transactional
public void decreaseNovelFeedCount(Novel novel) {
NovelStatistics novelStatistics = getNovelStatisticsOrException(novel);

novelStatistics.decreaseNovelFeedCount();
}

@Transactional(readOnly = true)
protected NovelStatistics getNovelStatisticsOrException(Novel novel) {
return novelStatisticsRepository.findByNovel(novel).orElseThrow(
() -> new InvalidNovelStatisticsException(NOVEL_STATISTICS_NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void createUserNovel(User user, UserNovelCreateRequest request) {
increaseStatistics(user, novel, request, attractivePoint);
}

protected UserNovel getUserNovelOrNull(User user, Novel novel) {
@Transactional(readOnly = true)
public UserNovel getUserNovelOrNull(User user, Novel novel) {
if (user == null) {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/websoso/WSSServer/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public NicknameValidation isNicknameAvailable(String nickname) {
return NicknameValidation.of(true);
}

@Transactional(readOnly = true)
public LoginResponse login(Long userId) {
User user = getUserOrException(userId);

Expand All @@ -46,6 +47,7 @@ public EmailGetResponse getEmail(User user) {
return EmailGetResponse.of(user.getEmail());
}

@Transactional(readOnly = true)
public User getUserOrException(Long userId) {
return userRepository.findById(userId).orElseThrow(() ->
new InvalidUserException(USER_NOT_FOUND, "user with the given id was not found"));
Expand Down

0 comments on commit 973c4d5

Please sign in to comment.