From 70d2baecedaacf82eed6afb0dd3b03f935a0f741 Mon Sep 17 00:00:00 2001 From: soohyun Date: Fri, 19 Jan 2024 03:40:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[#188]=20refactor:=20readonly=EB=93=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/app/toaster/service/UserService.java | 3 +++ .../com/app/toaster/service/category/CategoryService.java | 6 +++--- .../java/com/app/toaster/service/search/SearchService.java | 2 ++ .../java/com/app/toaster/service/timer/TimerService.java | 2 +- .../java/com/app/toaster/service/toast/ToastService.java | 1 - 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/linkmind/src/main/java/com/app/toaster/service/UserService.java b/linkmind/src/main/java/com/app/toaster/service/UserService.java index ad6b1206..34471f02 100644 --- a/linkmind/src/main/java/com/app/toaster/service/UserService.java +++ b/linkmind/src/main/java/com/app/toaster/service/UserService.java @@ -33,6 +33,7 @@ public class UserService { private final ToastRepository toastRepository; private final CategoryRepository categoryRepository; + @Transactional(readOnly = true) public MyPageResponse getMyPage(Long userId){ User user = userRepository.findByUserId(userId) .orElseThrow(()-> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage())); @@ -59,6 +60,7 @@ public Boolean allowedPushNotification(Long userId, Boolean fcmIsAllowed) { return fcmIsAllowed; } + @Transactional(readOnly = true) public SettingResponse getSettings(Long userId){ User user = userRepository.findByUserId(userId) .orElseThrow(()-> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage())); @@ -68,6 +70,7 @@ public SettingResponse getSettings(Long userId){ ); } + @Transactional(readOnly = true) public MainPageResponseDto getMainPage(Long userId){ User user = userRepository.findByUserId(userId) .orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage())); diff --git a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java index 9c7cef77..22dceffe 100644 --- a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java +++ b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java @@ -90,7 +90,7 @@ public void deleteCategory(final ArrayList deleteCategoryDto) { } } - + @Transactional(readOnly = true) public CategoriesResponse getCategories(final Long userId) { User presentUser = findUser(userId); @@ -104,7 +104,7 @@ public CategoriesResponse getCategories(final Long userId) { ).collect(Collectors.toList())); } - + @Transactional public GetCategoryResponseDto getCategory(final Long userId, final Long categoryId, final ToastFilter filter) { User presentUser = findUser(userId); if (categoryId == 0) { @@ -165,7 +165,7 @@ private User findUser(Long userId) { () -> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage()) ); } - + @Transactional(readOnly = true) public DuplicatedResponse checkDuplicatedTitle(Long userId, String title) { return DuplicatedResponse.of(categoryRepository.existsCategoriesByUserAndTitle(findUser(userId), title)); diff --git a/linkmind/src/main/java/com/app/toaster/service/search/SearchService.java b/linkmind/src/main/java/com/app/toaster/service/search/SearchService.java index 3fdbbc47..f1f78837 100644 --- a/linkmind/src/main/java/com/app/toaster/service/search/SearchService.java +++ b/linkmind/src/main/java/com/app/toaster/service/search/SearchService.java @@ -4,6 +4,7 @@ import java.util.stream.Collectors; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.app.toaster.common.dto.ApiResponse; import com.app.toaster.controller.response.search.CategoryResult; @@ -34,6 +35,7 @@ public class SearchService { private final UserRepository userRepository; private final CategoryRepository categoryRepository; + @Transactional(readOnly = true) public ApiResponse searchMain(Long userId, String searchParam){ if(searchParam.isBlank()){ throw new BadRequestException(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_URL.getMessage()); diff --git a/linkmind/src/main/java/com/app/toaster/service/timer/TimerService.java b/linkmind/src/main/java/com/app/toaster/service/timer/TimerService.java index cf8128fb..b4e7ec53 100644 --- a/linkmind/src/main/java/com/app/toaster/service/timer/TimerService.java +++ b/linkmind/src/main/java/com/app/toaster/service/timer/TimerService.java @@ -92,7 +92,7 @@ public void createTimer(Long userId, CreateTimerRequestDto createTimerRequestDto System.out.println("test 성공"); } } - + @Transactional(readOnly = true) public GetTimerResponseDto getTimer(Long userId, Long timerId){ Reminder reminder = timerRepository.findById(timerId) .orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_TIMER, Error.NOT_FOUND_TIMER.getMessage())); diff --git a/linkmind/src/main/java/com/app/toaster/service/toast/ToastService.java b/linkmind/src/main/java/com/app/toaster/service/toast/ToastService.java index 306f956b..1073cdb3 100644 --- a/linkmind/src/main/java/com/app/toaster/service/toast/ToastService.java +++ b/linkmind/src/main/java/com/app/toaster/service/toast/ToastService.java @@ -81,7 +81,6 @@ public void createToast(Long userId, SaveToastDto saveToastDto){ } } - @Transactional public IsReadResponse readToast(Long userId, IsReadDto isReadDto){ User presentUser = userRepository.findByUserId(userId).orElseThrow( From 02ba7c8880562daa189f932b8f29084c5b1bfb9f Mon Sep 17 00:00:00 2001 From: mmihye Date: Fri, 19 Jan 2024 03:44:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#184]=20fix:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=A6=84=20=EC=A4=91=EB=B3=B5=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=9C=A0=EC=A0=80=EB=A7=88=EB=8B=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/app/toaster/infrastructure/CategoryRepository.java | 2 +- .../java/com/app/toaster/service/category/CategoryService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linkmind/src/main/java/com/app/toaster/infrastructure/CategoryRepository.java b/linkmind/src/main/java/com/app/toaster/infrastructure/CategoryRepository.java index ceeaa3f7..8da9bc9c 100644 --- a/linkmind/src/main/java/com/app/toaster/infrastructure/CategoryRepository.java +++ b/linkmind/src/main/java/com/app/toaster/infrastructure/CategoryRepository.java @@ -64,7 +64,7 @@ void increasePriorityByOne(@Param("categoryId") Long categoryId, Long countAllByUser(User user); - Long countAllByTitle(String title); + Long countAllByTitleAndUser(String title); diff --git a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java index d5c04e67..9c9a2be9 100644 --- a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java +++ b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java @@ -57,7 +57,7 @@ public void createCategory(final Long userId, final CreateCategoryDto createCate Error.BAD_REQUEST_CREATE_CLIP_EXCEPTION.getMessage()); } - if(categoryRepository.countAllByTitle(createCategoryDto.categoryTitle())>0){ + if(categoryRepository.countAllByTitleAndUser(createCategoryDto.categoryTitle())>0){ throw new CustomException(Error.UNPROCESSABLE_CREATE_TIMER_EXCEPTION, Error.UNPROCESSABLE_CREATE_TIMER_EXCEPTION.getMessage()); }