From 9665278689e47a766e5dc969a649afdcd48fe894 Mon Sep 17 00:00:00 2001 From: taeyeon Date: Mon, 8 Apr 2024 00:06:52 +0900 Subject: [PATCH 1/3] create :: ServiceWithTransaction --- .../annotation/ServiceWithTransaction.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/mindway/server/v2/global/annotation/ServiceWithTransaction.java diff --git a/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithTransaction.java b/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithTransaction.java new file mode 100644 index 0000000..eff35dd --- /dev/null +++ b/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithTransaction.java @@ -0,0 +1,16 @@ +package com.mindway.server.v2.global.annotation; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Service +@Transactional(rollbackFor = {Exception.class}) +public @interface ServiceWithTransaction { +} From df3cb191f356323ee84762bf04106cfc567df93f Mon Sep 17 00:00:00 2001 From: taeyeon Date: Mon, 8 Apr 2024 00:07:06 +0900 Subject: [PATCH 2/3] create :: ServiceWithReadOnlyTransaction --- .../ServiceWithReadOnlyTransaction.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/mindway/server/v2/global/annotation/ServiceWithReadOnlyTransaction.java diff --git a/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithReadOnlyTransaction.java b/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithReadOnlyTransaction.java new file mode 100644 index 0000000..05ef828 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/global/annotation/ServiceWithReadOnlyTransaction.java @@ -0,0 +1,16 @@ +package com.mindway.server.v2.global.annotation; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Service +@Transactional(readOnly = true, rollbackFor = {Exception.class}) +public @interface ServiceWithReadOnlyTransaction { +} From 587f03fd681f61b9fce42a3ab86a8797813fa352 Mon Sep 17 00:00:00 2001 From: taeyeon Date: Mon, 8 Apr 2024 00:07:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor=20::=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/domain/auth/service/impl/LogoutServiceImpl.java | 6 ++---- .../domain/auth/service/impl/ReissueTokenServiceImpl.java | 6 ++---- .../v2/domain/auth/service/impl/SignInServiceImpl.java | 6 ++---- .../domain/order/service/impl/BookRequestServiceImpl.java | 6 ++---- .../order/service/impl/DeleteBookOrderServiceImpl.java | 6 ++---- .../domain/order/service/impl/GetBookOrdersServiceImpl.java | 6 ++---- .../order/service/impl/UpdateBookOrderServiceImpl.java | 6 ++---- .../v2/domain/user/service/impl/GetMyOrdersServiceImpl.java | 6 ++---- .../v2/domain/user/service/impl/UserInfoServiceImpl.java | 6 ++---- 9 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java index 4a15155..2329e9d 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java @@ -6,13 +6,11 @@ import com.mindway.server.v2.domain.auth.service.LogoutService; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service -@Transactional(rollbackFor = {Exception.class}) @RequiredArgsConstructor +@ServiceWithTransaction public class LogoutServiceImpl implements LogoutService { private final RefreshRepository refreshRepository; diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java index f3c1fda..488f973 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java @@ -8,14 +8,12 @@ import com.mindway.server.v2.domain.auth.service.ReissueTokenService; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.repository.UserRepository; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import com.mindway.server.v2.global.security.jwt.JwtProvider; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service -@Transactional(rollbackFor = {Exception.class}) @RequiredArgsConstructor +@ServiceWithTransaction public class ReissueTokenServiceImpl implements ReissueTokenService { private final JwtProvider jwtProvider; diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java index f3c39e6..26c1512 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java @@ -9,6 +9,7 @@ import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.entity.StudentNum; import com.mindway.server.v2.domain.user.repository.UserRepository; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import com.mindway.server.v2.global.security.jwt.JwtProvider; import gauth.GAuth; import gauth.GAuthToken; @@ -17,15 +18,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.util.UUID; -@Service @RequiredArgsConstructor -@Transactional(rollbackFor = {Exception.class}) +@ServiceWithTransaction @Slf4j public class SignInServiceImpl implements SignInService { diff --git a/src/main/java/com/mindway/server/v2/domain/order/service/impl/BookRequestServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/order/service/impl/BookRequestServiceImpl.java index fd7c242..0cbad23 100644 --- a/src/main/java/com/mindway/server/v2/domain/order/service/impl/BookRequestServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/order/service/impl/BookRequestServiceImpl.java @@ -8,13 +8,11 @@ import com.mindway.server.v2.domain.order.util.OrdersConverter; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service @RequiredArgsConstructor -@Transactional(rollbackFor = {Exception.class}) +@ServiceWithTransaction public class BookRequestServiceImpl implements BookRequestService { private final UserUtil userUtil; diff --git a/src/main/java/com/mindway/server/v2/domain/order/service/impl/DeleteBookOrderServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/order/service/impl/DeleteBookOrderServiceImpl.java index 8a687fd..bad6a2b 100644 --- a/src/main/java/com/mindway/server/v2/domain/order/service/impl/DeleteBookOrderServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/order/service/impl/DeleteBookOrderServiceImpl.java @@ -8,13 +8,11 @@ import com.mindway.server.v2.domain.user.entity.Authority; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service @RequiredArgsConstructor -@Transactional(rollbackFor = {Exception.class}) +@ServiceWithTransaction public class DeleteBookOrderServiceImpl implements DeleteBookOrderService { private final OrdersRepository ordersRepository; private final UserUtil userUtil; diff --git a/src/main/java/com/mindway/server/v2/domain/order/service/impl/GetBookOrdersServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/order/service/impl/GetBookOrdersServiceImpl.java index 516096e..0c5d333 100644 --- a/src/main/java/com/mindway/server/v2/domain/order/service/impl/GetBookOrdersServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/order/service/impl/GetBookOrdersServiceImpl.java @@ -8,16 +8,14 @@ import com.mindway.server.v2.domain.user.entity.Authority; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithReadOnlyTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; -@Service @RequiredArgsConstructor -@Transactional(readOnly = true, rollbackFor = {Exception.class}) +@ServiceWithReadOnlyTransaction public class GetBookOrdersServiceImpl implements GetBookOrdersService { private final UserUtil userUtil; private final OrdersRepository ordersRepository; diff --git a/src/main/java/com/mindway/server/v2/domain/order/service/impl/UpdateBookOrderServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/order/service/impl/UpdateBookOrderServiceImpl.java index 845c145..3c9e1ce 100644 --- a/src/main/java/com/mindway/server/v2/domain/order/service/impl/UpdateBookOrderServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/order/service/impl/UpdateBookOrderServiceImpl.java @@ -8,13 +8,11 @@ import com.mindway.server.v2.domain.order.service.UpdateBookOrderService; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service @RequiredArgsConstructor -@Transactional(rollbackFor = {Exception.class}) +@ServiceWithTransaction public class UpdateBookOrderServiceImpl implements UpdateBookOrderService { private final UserUtil userUtil; private final OrdersRepository ordersRepository; diff --git a/src/main/java/com/mindway/server/v2/domain/user/service/impl/GetMyOrdersServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/user/service/impl/GetMyOrdersServiceImpl.java index 60fa5fc..1e3e2b9 100644 --- a/src/main/java/com/mindway/server/v2/domain/user/service/impl/GetMyOrdersServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/user/service/impl/GetMyOrdersServiceImpl.java @@ -6,16 +6,14 @@ import com.mindway.server.v2.domain.user.presentation.dto.response.MyOrdersResponse; import com.mindway.server.v2.domain.user.service.GetMyOrdersService; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithReadOnlyTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; -@Service @RequiredArgsConstructor -@Transactional(readOnly = true, rollbackFor = {Exception.class}) +@ServiceWithReadOnlyTransaction public class GetMyOrdersServiceImpl implements GetMyOrdersService { private final UserUtil userUtil; diff --git a/src/main/java/com/mindway/server/v2/domain/user/service/impl/UserInfoServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/user/service/impl/UserInfoServiceImpl.java index fefa508..801d23d 100644 --- a/src/main/java/com/mindway/server/v2/domain/user/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/user/service/impl/UserInfoServiceImpl.java @@ -4,13 +4,11 @@ import com.mindway.server.v2.domain.user.presentation.dto.response.UserInfoResponse; import com.mindway.server.v2.domain.user.service.UserInfoService; import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithReadOnlyTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service @RequiredArgsConstructor -@Transactional(readOnly = true, rollbackFor = {Exception.class}) +@ServiceWithReadOnlyTransaction public class UserInfoServiceImpl implements UserInfoService { private final UserUtil userUtil;