From 6225c012b2cb86e2ce408a07e94610ef96c54e23 Mon Sep 17 00:00:00 2001 From: 1223v <1223v@naver.com> Date: Sun, 24 Mar 2024 21:15:14 +0900 Subject: [PATCH 01/11] =?UTF-8?q?Fix:=20cookie=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/readyvery/readyverydemo/config/JwtConfig.java | 6 ++---- .../security/jwt/service/sendmanger/TokenSendManager.java | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/config/JwtConfig.java b/src/main/java/com/readyvery/readyverydemo/config/JwtConfig.java index 955afb0..0033740 100644 --- a/src/main/java/com/readyvery/readyverydemo/config/JwtConfig.java +++ b/src/main/java/com/readyvery/readyverydemo/config/JwtConfig.java @@ -18,7 +18,6 @@ public class JwtConfig { private final String refreshTokenName; private final String userFrontendUrl; private final String guestFrontendUrl; - private final String cookieDomain; private final Algorithm algorithm; public static final String ACCESS_TOKEN_SUBJECT = "AccessToken"; @@ -35,8 +34,8 @@ public JwtConfig( @Value("${jwt.access.cookie}") String accessTokenName, @Value("${jwt.refresh.cookie}") String refreshTokenName, @Value("${jwt.redirect-uri-user}") String userFrontendUrl, - @Value("${jwt.redirect-uri-guest}") String guestFrontendUrl, - @Value("${jwt.cookie.domain}") String cookieDomain + @Value("${jwt.redirect-uri-guest}") String guestFrontendUrl + ) { this.secretKey = secretKey; this.accessTokenExpirationPeriod = accessTokenExpirationPeriod; @@ -45,7 +44,6 @@ public JwtConfig( this.refreshTokenName = refreshTokenName; this.userFrontendUrl = userFrontendUrl; this.guestFrontendUrl = guestFrontendUrl; - this.cookieDomain = cookieDomain; this.algorithm = initializeAlgorithm(secretKey); } diff --git a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/sendmanger/TokenSendManager.java b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/sendmanger/TokenSendManager.java index 7f4a932..d42483f 100644 --- a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/sendmanger/TokenSendManager.java +++ b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/sendmanger/TokenSendManager.java @@ -20,7 +20,6 @@ public void addTokenCookie(HttpServletResponse response, String name, String val Cookie cookie = new Cookie(name, value); cookie.setHttpOnly(httpOnly); cookie.setPath(path); - //cookie.setDomain(jwtConfig.getCookieDomain()); cookie.setMaxAge(maxAge); response.addCookie(cookie); From b8c152c0c99676bbc829384714fa883867c13edb Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 01:20:46 +0900 Subject: [PATCH 02/11] =?UTF-8?q?Feat:=20=EA=B2=B0=EC=A0=9C=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EB=95=8C=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/UserRepository.java | 6 ++++++ .../src/order/OrderServiceImpl.java | 17 +++++++++++++++++ .../src/user/UserServiceFacade.java | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/main/java/com/readyvery/readyverydemo/domain/repository/UserRepository.java b/src/main/java/com/readyvery/readyverydemo/domain/repository/UserRepository.java index 60f5241..2dd5423 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/repository/UserRepository.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/repository/UserRepository.java @@ -3,11 +3,17 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Lock; import com.readyvery.readyverydemo.domain.SocialType; import com.readyvery.readyverydemo.domain.UserInfo; +import jakarta.persistence.LockModeType; + public interface UserRepository extends JpaRepository { + @Lock(LockModeType.PESSIMISTIC_WRITE) + Optional findUserInfoById(Long id); + Optional findByEmail(String email); Optional findByRefreshToken(String refreshToken); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 5efbcff..3629e94 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -67,6 +67,7 @@ import com.readyvery.readyverydemo.src.order.dto.TossCancelReq; import com.readyvery.readyverydemo.src.order.dto.TosspaymentDto; import com.readyvery.readyverydemo.src.order.dto.TosspaymentMakeRes; +import com.readyvery.readyverydemo.src.user.UserServiceFacade; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; @@ -82,6 +83,7 @@ public class OrderServiceImpl implements OrderService { private final FoodieRepository foodieRepository; private final FoodieOptionRepository foodieOptionRepository; private final UserRepository userRepository; + private final UserServiceFacade userServiceFacade; private final StoreRepository storeRepository; private final OrderMapper orderMapper; private final TossPaymentConfig tosspaymentConfig; @@ -307,7 +309,9 @@ private void cartOrder(Cart cart) { @Transactional public PaySuccess tossPaymentSuccess(String paymentKey, String orderId, Long amount) { Order order = getOrder(orderId); + UserInfo user = userServiceFacade.getUserInfoWithPessimisticLock(order.getUserInfo().getId()); verifyOrder(order, amount); + verifyUsePoint(order, user); TosspaymentDto tosspaymentDto; if (amount > 0) { @@ -328,10 +332,23 @@ public PaySuccess tossPaymentSuccess(String paymentKey, String orderId, Long amo if (order.getPoint() < 0L) { Point point = orderMapper.orderToPoint(order); pointRepository.save(point); + userServiceFacade.saveUserPoint(user, user.getPoint() + order.getPoint()); } return orderMapper.tosspaymentDtoToPaySuccess(TOSSPAYMENT_SUCCESS_MESSAGE); } + private void verifyUsePoint(Order order, UserInfo user) { + // 포인트 사용 X + if (order.getPoint() >= 0L) { + return; + } + // 유저 포인트 충분 + if (user.getPoint() + order.getPoint() >= 0L) { + return; + } + throw new BusinessLogicException(ExceptionCode.POINT_NOT_ENOUGH); + } + private TosspaymentDto makeZeroPaymentDto(String paymentKey) { return TosspaymentDto.builder() .paymentKey(paymentKey) diff --git a/src/main/java/com/readyvery/readyverydemo/src/user/UserServiceFacade.java b/src/main/java/com/readyvery/readyverydemo/src/user/UserServiceFacade.java index 8efbec3..02365f9 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/user/UserServiceFacade.java +++ b/src/main/java/com/readyvery/readyverydemo/src/user/UserServiceFacade.java @@ -21,6 +21,12 @@ public UserInfo getUserInfo(Long id) { ); } + public UserInfo getUserInfoWithPessimisticLock(Long id) { + return userRepository.findUserInfoById(id).orElseThrow( + () -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND) + ); + } + public UserInfo getUserInfoByEmail(String email) { return userRepository.findByEmail(email).orElseThrow( () -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND) @@ -32,4 +38,9 @@ public void updateUserPhone(UserInfo userInfo, String phoneNumber) { userInfo.updatePhone(phoneNumber); userRepository.save(userInfo); } + + public void saveUserPoint(UserInfo user, long point) { + user.setPoint(point); + userRepository.save(user); + } } From 5d5c0eed8fbeca725fcfa546dd40a6ebb637c39d Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:04:48 +0900 Subject: [PATCH 03/11] =?UTF-8?q?Fix:=20=EC=B7=A8=EC=86=8C=EC=8B=9C=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B3=B5=EA=B5=AC=20=EB=9D=BD=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyvery/readyverydemo/src/order/OrderServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 3629e94..3d7e858 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -382,13 +382,14 @@ public CurrentRes getCurrent(String orderId) { @Override @Transactional public Object cancelTossPayment(CustomUserDetails userDetails, TossCancelReq tossCancelReq) { - UserInfo user = getUserInfo(userDetails); + UserInfo user = userServiceFacade.getUserInfoWithPessimisticLock(userDetails.getId()); Order order = getOrder(tossCancelReq.getOrderId()); verifyCancel(order, user); TosspaymentDto tosspaymentDto = requestTossPaymentCancel(order.getPaymentKey()); applyCancelTosspaymentDto(order, tosspaymentDto); + userServiceFacade.saveUserPoint(user, user.getPoint() - order.getPoint()); ordersRepository.save(order); return orderMapper.tosspaymentDtoToCancelRes(); @@ -447,7 +448,6 @@ private void applyCancelTosspaymentDto(Order order, TosspaymentDto tosspaymentDt order.setPayStatus(false); order.getReceipt().setCancels(tosspaymentDto.getCancels().toString()); order.getReceipt().setStatus(tosspaymentDto.getStatus()); - order.getUserInfo().setPoint(order.getUserInfo().getPoint() - order.getPoint()); if (order.getCoupon() != null) { order.getCoupon().setUseCount(order.getCoupon().getUseCount() - 1); } From ec3e4e313a361926b1cf745c53b2223d83c9cd51 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:16:03 +0900 Subject: [PATCH 04/11] =?UTF-8?q?Fix:=200=EC=9B=90=20=EC=B7=A8=EC=86=8C?= =?UTF-8?q?=EC=8B=9C=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyverydemo/src/order/OrderServiceImpl.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 3d7e858..84a0870 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -385,8 +385,12 @@ public Object cancelTossPayment(CustomUserDetails userDetails, TossCancelReq tos UserInfo user = userServiceFacade.getUserInfoWithPessimisticLock(userDetails.getId()); Order order = getOrder(tossCancelReq.getOrderId()); verifyCancel(order, user); - - TosspaymentDto tosspaymentDto = requestTossPaymentCancel(order.getPaymentKey()); + TosspaymentDto tosspaymentDto = null; + if (order.getAmount() > 0L) { + tosspaymentDto = requestTossPaymentCancel(order.getPaymentKey()); + } else { + tosspaymentDto = makeZeroPaymentCancelDto(); + } applyCancelTosspaymentDto(order, tosspaymentDto); userServiceFacade.saveUserPoint(user, user.getPoint() - order.getPoint()); @@ -395,6 +399,13 @@ public Object cancelTossPayment(CustomUserDetails userDetails, TossCancelReq tos return orderMapper.tosspaymentDtoToCancelRes(); } + private TosspaymentDto makeZeroPaymentCancelDto() { + return TosspaymentDto.builder() + .cancels(",=단순 변심") + .status("CANCELED") + .build(); + } + @Override @Transactional public HistoryDetailRes getReceipt(CustomUserDetails userDetails, String orderId) { From 8d1be6dba0be8da33261c7674546eb75a773345e Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:18:01 +0900 Subject: [PATCH 05/11] =?UTF-8?q?Fix:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=82=AC=EC=9A=A9=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/readyvery/readyverydemo/src/order/OrderServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 84a0870..7021a01 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -536,7 +536,6 @@ private void applyTosspaymentDto(Order order, TosspaymentDto tosspaymentDto) { order.setPayStatus(true); order.getCart().setIsOrdered(true); order.setMessage(TOSSPAYMENT_SUCCESS_MESSAGE); - order.getUserInfo().setPoint(order.getUserInfo().getPoint() + order.getPoint()); if (order.getCoupon() != null) { order.getCoupon().setUseCount(order.getCoupon().getUseCount() + 1); } From 401f0fd61213cd7e57b52dde35b2e1c11c73e97e Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:37:53 +0900 Subject: [PATCH 06/11] =?UTF-8?q?Feat:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=ED=8D=BC=EC=82=AC=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/point/PointServiceFacade.java | 21 +++++++++++++++++++ .../src/point/PointServiceImpl.java | 5 ++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java new file mode 100644 index 0000000..9f5aa03 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java @@ -0,0 +1,21 @@ +package com.readyvery.readyverydemo.src.point; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.readyvery.readyverydemo.domain.Point; +import com.readyvery.readyverydemo.domain.UserInfo; +import com.readyvery.readyverydemo.domain.repository.PointRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class PointServiceFacade { + private final PointRepository pointRepository; + + public List findAllByUserInfo(UserInfo userInfo) { + return pointRepository.findAllByUserInfo(userInfo); + } +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java index 1c48e0d..6be58eb 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java @@ -3,7 +3,6 @@ import org.springframework.stereotype.Service; import com.readyvery.readyverydemo.domain.UserInfo; -import com.readyvery.readyverydemo.domain.repository.PointRepository; import com.readyvery.readyverydemo.domain.repository.UserRepository; import com.readyvery.readyverydemo.global.exception.BusinessLogicException; import com.readyvery.readyverydemo.global.exception.ExceptionCode; @@ -18,7 +17,7 @@ @RequiredArgsConstructor public class PointServiceImpl implements PointService { private final UserRepository userRepository; - private final PointRepository pointRepository; + private final PointServiceFacade pointServiceFacade; private final PointMapper pointMapper; @Override @@ -30,7 +29,7 @@ public GetPointRes getPoint(CustomUserDetails userDetails) { @Override public GetPointHistoryRes getPointHistory(CustomUserDetails userDetails) { UserInfo userInfo = getUserInfo(userDetails.getId()); - return pointMapper.toGetPointHistoryRes(pointRepository.findAllByUserInfo(userInfo)); + return pointMapper.toGetPointHistoryRes(pointServiceFacade.findAllByUserInfo(userInfo)); } private UserInfo getUserInfo(Long id) { From a25bff0494ff973f76748ff5cdfecae8b8660412 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:38:36 +0900 Subject: [PATCH 07/11] =?UTF-8?q?Refactor:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8?= =?UTF-8?q?=20=EB=82=B4=EB=B6=80=20=EC=9C=A0=EC=A0=80=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/point/PointServiceImpl.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java index 6be58eb..f214604 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceImpl.java @@ -3,38 +3,30 @@ import org.springframework.stereotype.Service; import com.readyvery.readyverydemo.domain.UserInfo; -import com.readyvery.readyverydemo.domain.repository.UserRepository; -import com.readyvery.readyverydemo.global.exception.BusinessLogicException; -import com.readyvery.readyverydemo.global.exception.ExceptionCode; import com.readyvery.readyverydemo.security.jwt.dto.CustomUserDetails; import com.readyvery.readyverydemo.src.point.dto.GetPointHistoryRes; import com.readyvery.readyverydemo.src.point.dto.GetPointRes; import com.readyvery.readyverydemo.src.point.dto.PointMapper; +import com.readyvery.readyverydemo.src.user.UserServiceFacade; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class PointServiceImpl implements PointService { - private final UserRepository userRepository; + private final UserServiceFacade userServiceFacade; private final PointServiceFacade pointServiceFacade; private final PointMapper pointMapper; @Override public GetPointRes getPoint(CustomUserDetails userDetails) { - UserInfo userInfo = getUserInfo(userDetails.getId()); + UserInfo userInfo = userServiceFacade.getUserInfo(userDetails.getId()); return pointMapper.toGetPointRes(userInfo.getPoint()); } @Override public GetPointHistoryRes getPointHistory(CustomUserDetails userDetails) { - UserInfo userInfo = getUserInfo(userDetails.getId()); + UserInfo userInfo = userServiceFacade.getUserInfo(userDetails.getId()); return pointMapper.toGetPointHistoryRes(pointServiceFacade.findAllByUserInfo(userInfo)); } - - private UserInfo getUserInfo(Long id) { - return userRepository.findById(id).orElseThrow( - () -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND) - ); - } } From 5877dadae06b21cee2fc1300d9b74b21c88924db Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 02:52:45 +0900 Subject: [PATCH 08/11] =?UTF-8?q?Fix:=20=EC=B7=A8=EC=86=8C=EC=8B=9C=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=82=B4=EC=97=AD=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/readyvery/readyverydemo/domain/Point.java | 2 ++ .../domain/repository/PointRepository.java | 4 ++++ .../global/exception/ExceptionCode.java | 3 ++- .../readyverydemo/src/order/OrderServiceImpl.java | 5 +++++ .../readyverydemo/src/point/PointServiceFacade.java | 13 +++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Point.java b/src/main/java/com/readyvery/readyverydemo/domain/Point.java index e5904a8..49feb53 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/Point.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/Point.java @@ -15,8 +15,10 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; @Getter +@Setter @Entity @Builder @AllArgsConstructor diff --git a/src/main/java/com/readyvery/readyverydemo/domain/repository/PointRepository.java b/src/main/java/com/readyvery/readyverydemo/domain/repository/PointRepository.java index 4a99c2a..d44f65b 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/repository/PointRepository.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/repository/PointRepository.java @@ -1,12 +1,16 @@ package com.readyvery.readyverydemo.domain.repository; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import com.readyvery.readyverydemo.domain.Order; import com.readyvery.readyverydemo.domain.Point; import com.readyvery.readyverydemo.domain.UserInfo; public interface PointRepository extends JpaRepository { List findAllByUserInfo(UserInfo userInfo); + + Optional findByOrder(Order order); } diff --git a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java index ec11657..e99b629 100644 --- a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java +++ b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java @@ -35,7 +35,8 @@ public enum ExceptionCode { POINT_NOT_ENOUGH(400, "Point is not enough."), INVALID_INPUT(400, "Invalid input."), UNAUTHORIZED(400, "Already User"), - AUTH_ERROR(403, "Auth Error"); + AUTH_ERROR(403, "Auth Error"), + POINT_NOT_FOUND(403, "Point not found"); private int status; private String message; diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 7021a01..e5c14e8 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -67,6 +67,7 @@ import com.readyvery.readyverydemo.src.order.dto.TossCancelReq; import com.readyvery.readyverydemo.src.order.dto.TosspaymentDto; import com.readyvery.readyverydemo.src.order.dto.TosspaymentMakeRes; +import com.readyvery.readyverydemo.src.point.PointServiceFacade; import com.readyvery.readyverydemo.src.user.UserServiceFacade; import jakarta.transaction.Transactional; @@ -91,6 +92,7 @@ public class OrderServiceImpl implements OrderService { private final ReceiptRepository receiptRepository; private final CouponRepository couponRepository; private final PointRepository pointRepository; + private final PointServiceFacade pointServiceFacade; @Override public FoodyDetailRes getFoody(Long storeId, Long foodyId, Long inout) { @@ -384,6 +386,8 @@ public CurrentRes getCurrent(String orderId) { public Object cancelTossPayment(CustomUserDetails userDetails, TossCancelReq tossCancelReq) { UserInfo user = userServiceFacade.getUserInfoWithPessimisticLock(userDetails.getId()); Order order = getOrder(tossCancelReq.getOrderId()); + Point point = pointServiceFacade.getPointByOrder(order); + verifyCancel(order, user); TosspaymentDto tosspaymentDto = null; if (order.getAmount() > 0L) { @@ -394,6 +398,7 @@ public Object cancelTossPayment(CustomUserDetails userDetails, TossCancelReq tos applyCancelTosspaymentDto(order, tosspaymentDto); userServiceFacade.saveUserPoint(user, user.getPoint() - order.getPoint()); + pointServiceFacade.cancelPoint(point); ordersRepository.save(order); return orderMapper.tosspaymentDtoToCancelRes(); diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java index 9f5aa03..d447082 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java +++ b/src/main/java/com/readyvery/readyverydemo/src/point/PointServiceFacade.java @@ -4,9 +4,12 @@ import org.springframework.stereotype.Service; +import com.readyvery.readyverydemo.domain.Order; import com.readyvery.readyverydemo.domain.Point; import com.readyvery.readyverydemo.domain.UserInfo; import com.readyvery.readyverydemo.domain.repository.PointRepository; +import com.readyvery.readyverydemo.global.exception.BusinessLogicException; +import com.readyvery.readyverydemo.global.exception.ExceptionCode; import lombok.RequiredArgsConstructor; @@ -18,4 +21,14 @@ public class PointServiceFacade { public List findAllByUserInfo(UserInfo userInfo) { return pointRepository.findAllByUserInfo(userInfo); } + + public Point getPointByOrder(Order order) { + return pointRepository.findByOrder(order) + .orElseThrow(() -> new BusinessLogicException(ExceptionCode.POINT_NOT_FOUND)); + } + + public void cancelPoint(Point point) { + point.setIsDeleted(true); + pointRepository.save(point); + } } From 3489e4283a8921cceec4c6d91a6ecc57f85480a3 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 03:15:31 +0900 Subject: [PATCH 09/11] =?UTF-8?q?Fix:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=ED=9E=88=EC=8A=A4=ED=86=A0=EB=A6=AC=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=95=88=EB=B3=B4=EC=9D=B4=EA=B2=8C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyvery/readyverydemo/src/point/dto/PointMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/dto/PointMapper.java b/src/main/java/com/readyvery/readyverydemo/src/point/dto/PointMapper.java index ee00552..32b7c4f 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/point/dto/PointMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/point/dto/PointMapper.java @@ -21,13 +21,13 @@ public GetPointRes toGetPointRes(Long point) { public GetPointHistoryRes toGetPointHistoryRes(List points) { return GetPointHistoryRes .builder() - .history(points.stream().map(this::pointToPointDto).toList()) + .history(points.stream().filter(point -> !point.getIsDeleted()).map(this::pointToPointDto).toList()) .build(); } private PointDto pointToPointDto(Point point) { return PointDto.builder() - .point((point.getPoint() > 0 ? "+" : "") + point.getPoint()) // +1 or -1 + .point((point.getPoint() >= 0 ? "+" : "") + point.getPoint()) // +1 or -1 .date(point.getCreatedAt().format(DateTimeFormatter.ofPattern(DATE_FORMAT))) .status(point.getIsDeleted()) .store(point.getOrder().getStore().getName()) From e51442520acf5565e9c424159b36772aee9a68e8 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 03:17:43 +0900 Subject: [PATCH 10/11] =?UTF-8?q?Fix:=20=EC=A3=BC=EB=AC=B8=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - old에 complete 추가 / new에 제거 --- .../readyvery/readyverydemo/src/order/dto/OrderMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 287aceb..a3cba0c 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -237,6 +237,7 @@ public HistoryRes ordersToHistoryRes(List orders) { orders .stream() .filter(order -> order.getProgress() == PICKUP + || order.getProgress() == COMPLETE || order.getProgress() == FAIL || order.getProgress() == CANCEL) .map(this::orderToReceiptHistoryDto) @@ -265,8 +266,7 @@ public HistoryRes ordersToNewHistoryRes(List orders) { orders .stream() .filter(order -> order.getProgress() == ORDER - || order.getProgress() == MAKE - || order.getProgress() == COMPLETE) + || order.getProgress() == MAKE) .map(this::orderToReceiptHistoryDto) .toList()) .build(); From 6aaf7c85631d2ce509f955142405f96f53073efc Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Mon, 25 Mar 2024 03:47:40 +0900 Subject: [PATCH 11/11] =?UTF-8?q?Feat:=20=EC=82=AD=EC=A0=9C=20=EA=B0=80?= =?UTF-8?q?=EA=B2=8C=20=EC=95=88=EB=B3=B4=EC=9D=B4=EA=B2=8C=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/readyvery/readyverydemo/src/board/dto/BoardMapper.java | 2 +- .../com/readyvery/readyverydemo/src/order/dto/OrderMapper.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/board/dto/BoardMapper.java b/src/main/java/com/readyvery/readyverydemo/src/board/dto/BoardMapper.java index 41a7aac..30ae441 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/board/dto/BoardMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/board/dto/BoardMapper.java @@ -20,7 +20,7 @@ public BoardRes toBoardRes(List stores) { throw new BusinessLogicException(ExceptionCode.STORE_NOT_FOUND); } return BoardRes.builder() - .stores(stores.stream().map(this::toStoreDto).toList()) + .stores(stores.stream().filter(store -> !store.isDeleted()).map(this::toStoreDto).toList()) .build(); } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index a3cba0c..d165554 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -236,6 +236,7 @@ public HistoryRes ordersToHistoryRes(List orders) { .receipts( orders .stream() + .filter(order -> !order.getStore().isDeleted()) .filter(order -> order.getProgress() == PICKUP || order.getProgress() == COMPLETE || order.getProgress() == FAIL @@ -250,6 +251,7 @@ public HistoryRes ordersToFastOrderRes(List orders) { .receipts( orders .stream() + .filter(order -> !order.getStore().isDeleted()) .filter(order -> order.getCart().getCreatedAt() // 데이터 변경 시점 이후의 데이터만 가져옴 .isAfter(LocalDateTime.of(2023, 12, 6, 0, 0, 0))) @@ -265,6 +267,7 @@ public HistoryRes ordersToNewHistoryRes(List orders) { .receipts( orders .stream() + .filter(order -> !order.getStore().isDeleted()) .filter(order -> order.getProgress() == ORDER || order.getProgress() == MAKE) .map(this::orderToReceiptHistoryDto)