From c9a6f29014e96aa201d81d593bd61697817419e7 Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:00:41 +0900 Subject: [PATCH 01/46] =?UTF-8?q?docs:=20h2=EB=A1=9C=20=EB=B0=94=EB=80=8C?= =?UTF-8?q?=EC=96=B4=20=EC=9E=88=EB=8D=98=20local=20db=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=9D=84=20=EB=B3=80=EA=B2=BD=ED=95=9C=EB=8B=A4.=20(#?= =?UTF-8?q?427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index e7110b0c..61277fca 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,9 +1,9 @@ spring: datasource: - driver-class-name: org.h2.Driver - url: jdbc:h2:mem:test; - username: sa - password: + driver-class-name: ${db.driver} + url: ${db.url} + username: ${db.username} + password: ${db.password} jpa: hibernate: ddl-auto: create From 95bd8f4e3c735c5079b8250d7d15f039ee6366fa Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:01:25 +0900 Subject: [PATCH 02/46] =?UTF-8?q?bug:=20=EC=9E=90=EB=B0=94=20=ED=8A=B9?= =?UTF-8?q?=EC=84=B1=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=86=8C=EC=88=98?= =?UTF-8?q?=EC=A0=90=EC=9D=B4=20=EC=95=84=EB=8B=8C=200=EA=B0=92=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B3=84=EC=82=B0=EB=90=98=EB=8A=94=20=EA=B2=83?= =?UTF-8?q?=EC=9D=84=20=ED=95=B4=EA=B2=B0=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trendpick_pro/domain/coupon/entity/CouponCard.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/coupon/entity/CouponCard.java b/src/main/java/project/trendpick_pro/domain/coupon/entity/CouponCard.java index 73f0598f..83ea5e7b 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/entity/CouponCard.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/entity/CouponCard.java @@ -22,7 +22,7 @@ public class CouponCard extends BaseTimeEntity { private Long id; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "coupon", nullable = false) + @JoinColumn(name = "coupon") private Coupon coupon; @Column(name = "coupon_code", nullable = false, unique = true) @@ -66,8 +66,10 @@ && validateStatus() public void use(OrderItem orderItem, LocalDateTime dateTime) { settingStatusAndDate(dateTime); orderItem.applyCouponCard(this); + int discountPercent = this.coupon.getDiscountPercent(); + int price = orderItem.getOrderPrice() * discountPercent / 100; orderItem.discount( - orderItem.getOrderPrice() * (this.coupon.getDiscountPercent() / 100) + price ); } From 60a0e717270554e827aa90d6ae0a629eb7face11 Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:01:57 +0900 Subject: [PATCH 03/46] =?UTF-8?q?refactor:=20url=EA=B5=AC=EB=AC=B8?= =?UTF-8?q?=EC=97=90=20/=20=EC=B6=94=EA=B0=80=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/controller/CouponCardController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/coupon/controller/CouponCardController.java b/src/main/java/project/trendpick_pro/domain/coupon/controller/CouponCardController.java index 04e9c1b6..11c991e4 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/controller/CouponCardController.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/controller/CouponCardController.java @@ -29,21 +29,21 @@ public String issueCoupon(@PathVariable("couponId") Long couponId, HttpServletRe } @PreAuthorize("hasRole('MEMBER')") - @GetMapping("apply") + @GetMapping("/apply") @ResponseBody public List showApplicableCoupons(@RequestParam("orderItem") Long orderItemId) { return couponCardService.showCouponCardsByOrderItem(orderItemId); } @PreAuthorize("hasRole('MEMBER')") - @PostMapping("apply") + @PostMapping("/apply") public String applyCoupon(@RequestParam("couponCard") Long couponCardId, @RequestParam("orderItem") Long orderItemId, HttpServletRequest req) { - RsData result = couponCardService.apply(couponCardId, orderItemId); + RsData result = couponCardService.apply(couponCardId, orderItemId, LocalDateTime.now()); return processRequest(result, "쿠폰이 적용되었습니다.", req); } @PreAuthorize("hasRole('MEMBER')") - @PostMapping("cancel") + @PostMapping("/cancel") public String cancelCoupon(@RequestParam("orderItem") Long orderItemId, HttpServletRequest req) { RsData result = couponCardService.cancel(orderItemId); return processRequest(result, "쿠폰 적용이 취소되었습니다.", req); From 5ddfe4bfe00120f0038f17433c849708c74f6b1f Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:02:23 +0900 Subject: [PATCH 04/46] =?UTF-8?q?refactor:=20=EA=B2=A9=EB=A6=AC=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EA=B0=92=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=A9=EC=B6=9C=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trendpick_pro/domain/coupon/service/CouponCardService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/project/trendpick_pro/domain/coupon/service/CouponCardService.java b/src/main/java/project/trendpick_pro/domain/coupon/service/CouponCardService.java index c504748c..1ff225fa 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/service/CouponCardService.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/service/CouponCardService.java @@ -14,7 +14,7 @@ public interface CouponCardService { List showCouponCardsByOrderItem(Long orderItemId); - RsData apply(Long couponCardId, Long orderItemId); + RsData apply(Long couponCardId, Long orderItemId, LocalDateTime now); RsData cancel(Long orderItemId); From d54342981f896e5af3fd9b1ef1a4acaeb8e3b778 Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:02:40 +0900 Subject: [PATCH 05/46] =?UTF-8?q?refactor:=20=EC=9C=A0=EC=A7=80=EB=B3=B4?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CouponCardServiceImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java index f603246f..a11373e3 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java @@ -35,25 +35,25 @@ public RsData issue(Member member, Long couponId, LocalDateTime dateTime) { () -> new CouponNotFoundException("존재하지 않는 쿠폰입니다.")); int count = couponCardRepository.countByCouponIdAndMemberId(couponId, member.getId()); - RsData of = validateCouponCard(count, coupon); - if (of != null) { - return of; + RsData isValidate = validateCouponCard(count, coupon, dateTime); + if (isValidate != null) { + return isValidate; } CouponCard savedCouponCard = settingCouponCard(member, dateTime, coupon); - return RsData.of("S-1", coupon.getName() + " 쿠폰이 발급되었습니다."); + return RsData.of("S-1", coupon.getName() + " 쿠폰이 발급되었습니다."); } @Transactional @Override - public RsData apply(Long couponCardId, Long orderItemId) { + public RsData apply(Long couponCardId, Long orderItemId, LocalDateTime dateTime) { OrderItem orderItem = orderItemRepository.findById(orderItemId).orElseThrow( () -> new OrderItemNotFoundException("주문되지 않은 상품입니다.")); CouponCard couponCard = couponCardRepository.findById(couponCardId).orElseThrow( () -> new CouponNotFoundException("존재하지 않은 쿠폰입니다.")); - if (!couponCard.validate(orderItem, LocalDateTime.now())) + if (!couponCard.validate(orderItem, dateTime)) return RsData.of("F-1", "해당 주문상품에 적용된 쿠폰이 없습니다."); - couponCard.use(orderItem, LocalDateTime.now()); + couponCard.use(orderItem, dateTime); return RsData.of("S-1", "쿠폰이 적용되었습니다."); } @@ -83,12 +83,12 @@ private CouponCard settingCouponCard(Member member, LocalDateTime dateTime, Coup return savedCouponCard; } - private static RsData validateCouponCard(int count, Coupon coupon) { + private static RsData validateCouponCard(int count, Coupon coupon, LocalDateTime dateTime) { if(count > 0) return RsData.of("F-3", "이미 발급 받으신 쿠폰입니다."); if(!coupon.validateLimitCount()) return RsData.of("F-1", "수량이 모두 소진되었습니다."); - if(!coupon.validateLimitIssueDate(LocalDateTime.now())) + if(!coupon.validateLimitIssueDate(dateTime)) return RsData.of("F-2", "쿠폰 발급 가능 날짜가 지났습니다."); return null; } From 60ddf582899988b7b32b48b0a963818a196ef9de Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:03:08 +0900 Subject: [PATCH 06/46] =?UTF-8?q?refactor:=20=ED=95=84=EB=93=9C=EB=AA=85?= =?UTF-8?q?=EA=B3=BC=20=EB=8B=A4=EB=A5=B8=20=EC=BB=AC=EB=9F=BC=20=EB=84=A4?= =?UTF-8?q?=EC=9E=84=EC=9D=84=20=EC=82=AD=EC=A0=9C=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/trendpick_pro/domain/orders/entity/OrderItem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/project/trendpick_pro/domain/orders/entity/OrderItem.java b/src/main/java/project/trendpick_pro/domain/orders/entity/OrderItem.java index 61488fc0..0c10b00c 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/entity/OrderItem.java +++ b/src/main/java/project/trendpick_pro/domain/orders/entity/OrderItem.java @@ -33,7 +33,6 @@ public class OrderItem extends BaseTimeEntity { @Column(name = "order_price", nullable = false) private int orderPrice; - @Column(name = "total_price") private int orderItemByQuantity; @Column(name = "discount_price", nullable = false) From 521d2df0f1b406d1c309580b7a70731030d61c20 Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 21:03:20 +0900 Subject: [PATCH 07/46] =?UTF-8?q?refactor:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/tosspayment/controller/PaymentController.java | 4 ++-- .../global/tosspayment/service/PaymentService.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/project/trendpick_pro/global/tosspayment/controller/PaymentController.java b/src/main/java/project/trendpick_pro/global/tosspayment/controller/PaymentController.java index 38a17085..44e1dcae 100644 --- a/src/main/java/project/trendpick_pro/global/tosspayment/controller/PaymentController.java +++ b/src/main/java/project/trendpick_pro/global/tosspayment/controller/PaymentController.java @@ -39,8 +39,8 @@ public String PaymentTry( if (response.getStatus().equals("DONE")) { order.connectPayment( - response.getPaymentKey(), - "TossPayments " + response.getMethod() + "TossPayments" + response.getMethod(), + response.getPaymentKey() ); notificationService.create(rq.getMember(), order.getId()); return rq.redirectWithMsg("/trendpick/orders/%s".formatted(id), "주문이 완료되었습니다."); diff --git a/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java b/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java index b59dcf9f..e8a0f19b 100644 --- a/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java +++ b/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java @@ -13,6 +13,7 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Collections; +import java.util.Objects; @Service public class PaymentService { From 994516b6fd5367d888575358c92e72c79c7eb971 Mon Sep 17 00:00:00 2001 From: SoohoLee Date: Wed, 16 Aug 2023 22:00:21 +0900 Subject: [PATCH 08/46] =?UTF-8?q?bug:=20=EC=9E=AC=EA=B3=A0=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=EA=B0=90=EC=86=8C=20=EB=A1=9C=EC=A7=81=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(#429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orders/service/impl/OrderServiceImpl.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java index 613c6f14..ac58cda8 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java @@ -29,6 +29,7 @@ import project.trendpick_pro.domain.orders.repository.OrderRepository; import project.trendpick_pro.domain.orders.service.OrderService; import project.trendpick_pro.domain.product.entity.product.Product; +import project.trendpick_pro.domain.product.entity.productOption.ProductOption; import project.trendpick_pro.domain.product.exception.ProductNotFoundException; import project.trendpick_pro.domain.product.exception.ProductStockOutException; import project.trendpick_pro.domain.product.service.ProductService; @@ -91,6 +92,7 @@ public RsData productToOrder(Member member, Long id, int quantity, String size, List.of(OrderItem.of(productService.findById(id), quantity, size, color)) ) ); + log.info("재고 : {}", saveOrder.getOrderItems().get(0).getProduct().getProductOption().getStock()); OutboxMessage message = createOutboxMessage(saveOrder); kafkaProducerService.sendMessage(message.getId()); return RsData.of("S-1", "주문을 시작합니다."); @@ -105,7 +107,6 @@ public void tryOrder(String id) throws JsonProcessingException { .orElseThrow(() -> new OrderNotFoundException("존재하지 않는 주문 입니다.")); String email = order.getMember().getEmail(); try { - decreaseStock(order); order.updateStatus(OrderStatus.ORDERED); sendMessage(order.getId(), "Success", email); } catch (ProductStockOutException e) { @@ -214,16 +215,6 @@ private void sendMessage(Long orderId, String message, String email) throws Json kafkaProducerService.sendMessage(orderId, message, email); } - private static void decreaseStock(Order order) { - for (OrderItem orderItem : order.getOrderItems()) { - orderItem.getProduct().getProductOption().decreaseStock(orderItem.getQuantity()); - if (orderItem.getProduct().getProductOption().getStock() < 0) { - throw new ProductStockOutException("재고가 부족 합니다."); - } - log.info("재고 : {}", orderItem.getProduct().getProductOption().getStock()); - } - } - private Page settingOrderByMemberStatus(Member member, int offset) { Page findOrders; PageRequest pageable = PageRequest.of(offset, 10); From 8da2e16017c671102ced3c88a0f6805d679050ae Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:19:06 +0900 Subject: [PATCH 09/46] =?UTF-8?q?refactor:=20Withdraw=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20(=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=EB=B3=80=EA=B2=BD,=20SRP=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdmWithdrawController.java | 5 +- .../domain/withdraw/entity/WithdrawApply.java | 21 +++-- .../withdraw/service/WithdrawService.java | 6 +- .../service/impl/WithdrawServiceImpl.java | 83 +++++++++---------- 4 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java b/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java index c63aaebf..844c691c 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java @@ -26,12 +26,13 @@ public class AdmWithdrawController { @PreAuthorize("hasAuthority({'ADMIN', 'BRAND_ADMIN'})") @GetMapping("/withDrawList") public String showApplyList(Model model) { - Member member=rq.getRollMember(); + Member member= rq.getAdmin(); List withdrawApplies; + if(member.getRole().getValue().equals("ADMIN")) { withdrawApplies = withdrawService.findAll(); }else{ - withdrawApplies=withdrawService.findByWithdrawApplyId(member.getId()); + withdrawApplies=withdrawService.findAllWithdrawByApplicantId(member.getId()); } model.addAttribute("withdrawApplies", withdrawApplies); return "trendpick/admin/withDrawList"; diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/entity/WithdrawApply.java b/src/main/java/project/trendpick_pro/domain/withdraw/entity/WithdrawApply.java index bb624e73..d45c5a01 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/entity/WithdrawApply.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/entity/WithdrawApply.java @@ -5,6 +5,7 @@ import lombok.experimental.SuperBuilder; import project.trendpick_pro.domain.cash.entity.CashLog; import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; import java.time.LocalDateTime; @@ -35,18 +36,19 @@ public class WithdrawApply { private LocalDateTime cancelDate; private String msg; - public boolean isApplyDoneAvailable() { + public boolean checkAlreadyProcessed() { //이미 처리되었는지 확인 if (withdrawDate != null || withdrawCashLog != null || cancelDate != null) { - return false; + return true; } - return true; + return false; } - public void setApplyDone(Long cashLogId, String msg) { + public void setApplyDone(CashLog cashLog, String msg) { withdrawDate = LocalDateTime.now(); - this.withdrawCashLog = new CashLog(cashLogId); + this.withdrawCashLog = cashLog; this.msg = msg; + } public void setCancelDone(String msg) { @@ -54,8 +56,13 @@ public void setCancelDone(String msg) { this.msg = msg; } - public boolean isCancelAvailable() { - return isApplyDoneAvailable(); + static public WithdrawApply of(WithDrawApplyForm withDrawApplyForm, Member applicant){ + return WithdrawApply.builder() + .bankName(withDrawApplyForm.getBankName()) + .bankAccountNo(withDrawApplyForm.getBankAccountNo()) + .price(withDrawApplyForm.getPrice()) + .applicant(applicant) + .build(); } public boolean isApplyDone() { diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java b/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java index 60fc2353..3d6e6039 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java @@ -2,14 +2,16 @@ import project.trendpick_pro.domain.member.entity.Member; import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; import project.trendpick_pro.global.util.rsData.RsData; import java.util.List; public interface WithdrawService { - RsData apply(String bankName, String bankAccountNo, Integer price, Member applicant); + RsData apply(WithDrawApplyForm withDrawApplyForm, Member applicant); List findAll(); - List findByWithdrawApplyId(Long id); + List findAllWithdrawByApplicantId(Long id); RsData withdraw(Long withdrawApplyId); RsData cancelApply(Long withdrawApplyId); + int showRestCash(Member brandMember); } diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java b/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java index 30d5349c..bf69ae14 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java @@ -3,12 +3,13 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import project.trendpick_pro.domain.brand.entity.Brand; -import project.trendpick_pro.domain.brand.service.BrandService; import project.trendpick_pro.domain.cash.entity.CashLog; +import project.trendpick_pro.domain.cash.service.CashService; import project.trendpick_pro.domain.member.entity.Member; import project.trendpick_pro.domain.member.service.MemberService; +import project.trendpick_pro.domain.store.service.StoreService; import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; import project.trendpick_pro.domain.withdraw.repository.WithdrawApplyRepository; import project.trendpick_pro.domain.withdraw.service.WithdrawService; import project.trendpick_pro.global.util.rsData.RsData; @@ -18,35 +19,28 @@ @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class WithdrawServiceImpl implements WithdrawService { private final WithdrawApplyRepository withdrawApplyRepository; - + private final StoreService storeService; private final MemberService memberService; - private final BrandService brandService; + private final CashService cashService; @Transactional @Override - public RsData apply(String bankName, String bankAccountNo, Integer price, Member applicant) { - WithdrawApply withdrawApply = WithdrawApply.builder() - .bankName(bankName) - .bankAccountNo(bankAccountNo) - .price(price) - .applicant(applicant) - .build(); - withdrawApplyRepository.save(withdrawApply); + public RsData apply(WithDrawApplyForm withDrawApplyForm, Member applicant) { + WithdrawApply withdrawApply = withdrawApplyRepository.save(WithdrawApply.of(withDrawApplyForm, applicant)); return RsData.of("S-1", "출금 신청이 완료되었습니다.", withdrawApply); } - @Transactional(readOnly = true) @Override public List findAll() { return withdrawApplyRepository.findAll(); } - @Transactional(readOnly = true) @Override - public List findByWithdrawApplyId(Long id){ + public List findAllWithdrawByApplicantId(Long id){ return withdrawApplyRepository.findAllByApplicantId(id); } @@ -54,28 +48,12 @@ public List findByWithdrawApplyId(Long id){ public RsData withdraw(Long withdrawApplyId) { WithdrawApply withdrawApply = withdrawApplyRepository.findById(withdrawApplyId).orElse(null); - if (withdrawApply == null) { - return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); - } - long restCash = memberService.getRestCash(withdrawApply.getApplicant()); - - if (!withdrawApply.isApplyDoneAvailable()) { - return RsData.of("F-2", "이미 처리되었습니다."); - } - if (withdrawApply.getPrice() > restCash) { - return RsData.of("F-3", "예치금이 부족합니다."); - } - Brand brand=brandService.findByName(withdrawApply.getApplicant().getBrand()); - - CashLog cashLog = memberService.addCash( - withdrawApply.getApplicant().getBrand(), - withdrawApply.getPrice() * -1, - brand, - CashLog.EvenType.출금__통장입금 - ) - .getData().getCashLog(); + RsData validateResult = validateAvailableWithdraw(withdrawApply); //캐시 출금 검증 + if (validateResult.isFail()) return validateResult; - withdrawApply.setApplyDone(cashLog.getId(), "관리자에 의해서 처리되었습니다."); + CashLog cashLog = cashService.addCashLog(withdrawApply); + withdrawApply.setApplyDone(cashLog, "관리자에 의해서 처리되었습니다."); + memberService.completeWithdraw(withdrawApply); //출금 신청한거 완료됐어요. return RsData.of( "S-1", @@ -86,16 +64,13 @@ public RsData withdraw(Long withdrawApplyId) { ); } + @Transactional public RsData cancelApply(Long withdrawApplyId) { WithdrawApply withdrawApply = withdrawApplyRepository.findById(withdrawApplyId).orElse(null); - if (withdrawApply == null) { - return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); - } - if (!withdrawApply.isCancelAvailable()) { - return RsData.of("F-2", "취소가 불가능합니다."); - } + RsData validateResult = validateAvailableCancel(withdrawApply); //취소 가능한지 검증 + if (validateResult.isFail()) return validateResult; withdrawApply.setCancelDone("관리자에 의해서 취소되었습니다."); @@ -105,4 +80,28 @@ public RsData cancelApply(Long withdrawApplyId) { null ); } + + @Override + public int showRestCash(Member brandMember) { + return storeService.getRestCash(brandMember.getBrand()); + } + + private static RsData validateAvailableCancel(WithdrawApply withdrawApply) { + if (withdrawApply == null) + return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); + + if (!withdrawApply.checkAlreadyProcessed()) + return RsData.of("F-2", "이미 처리된 출금 신청 입니다."); + + return RsData.success(); + } + private RsData validateAvailableWithdraw(WithdrawApply withdrawApply) { + if (withdrawApply == null) + return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); + if (withdrawApply.checkAlreadyProcessed()) + return RsData.of("F-2", "이미 처리되었습니다."); + if (withdrawApply.getPrice() > withdrawApply.getApplicant().getRestCash()) + return RsData.of("F-3", "예치금이 부족합니다."); + return RsData.success(); + } } \ No newline at end of file From 9dba531a62a1857aaea909afb4e136b75c34ab2d Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:20:59 +0900 Subject: [PATCH 10/46] =?UTF-8?q?refactor:=20Store=EC=97=90=20=EC=BA=90?= =?UTF-8?q?=EC=8B=9C=20=EA=B4=80=EB=A0=A8=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/store/entity/Store.java | 16 +++++++++++++++- .../domain/store/service/StoreService.java | 2 ++ .../store/service/impl/StoreServiceImpl.java | 14 +++++++++++++- .../controller/WithdrawController.java | 18 ++++-------------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/store/entity/Store.java b/src/main/java/project/trendpick_pro/domain/store/entity/Store.java index 625c881e..6e67b88a 100644 --- a/src/main/java/project/trendpick_pro/domain/store/entity/Store.java +++ b/src/main/java/project/trendpick_pro/domain/store/entity/Store.java @@ -15,10 +15,24 @@ public class Store extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(unique = true) + @Column(name = "brand", unique = true) private String brand; + //정산 데이터 생성 -> 정산처리 -> 캐시 처리 + @Column(name = "rebate_cash") + private int rebatedCash; + public Store(String brand){ this.brand = brand; } + + public void addRebatedCash(int price) { + this.rebatedCash += price; + } + + public void withdrawRebatedCash(int price){ + if(this.rebatedCash <= price) + throw new IllegalArgumentException("출금 요청한 금액이 정산 금액보다 많습니다."); + this.rebatedCash -= price; + } } diff --git a/src/main/java/project/trendpick_pro/domain/store/service/StoreService.java b/src/main/java/project/trendpick_pro/domain/store/service/StoreService.java index f0593249..5d87c77e 100644 --- a/src/main/java/project/trendpick_pro/domain/store/service/StoreService.java +++ b/src/main/java/project/trendpick_pro/domain/store/service/StoreService.java @@ -5,4 +5,6 @@ public interface StoreService { Store save(Store store); Store findByBrand(String storeName); + void addRebateCash(String storeName, int calculateRebatePrice); + int getRestCash(String storeName); } diff --git a/src/main/java/project/trendpick_pro/domain/store/service/impl/StoreServiceImpl.java b/src/main/java/project/trendpick_pro/domain/store/service/impl/StoreServiceImpl.java index aab8df02..ab7da414 100644 --- a/src/main/java/project/trendpick_pro/domain/store/service/impl/StoreServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/store/service/impl/StoreServiceImpl.java @@ -9,6 +9,7 @@ @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class StoreServiceImpl implements StoreService { private final StoreRepository storeRepository; @@ -19,10 +20,21 @@ public Store save(Store store){ } @Override - @Transactional(readOnly = true) public Store findByBrand(String storeName) { return storeRepository.findByBrand(storeName).orElseThrow( () -> new IllegalArgumentException("해당 스토어는 존재하지 않는 스토어입니다.") ); } + + @Override + @Transactional + public void addRebateCash(String storeName, int calculateRebatePrice) { + Store store = findByBrand(storeName); + store.addRebatedCash(calculateRebatePrice); + } + + @Override + public int getRestCash(String storeName) { + return findByBrand(storeName).getRebatedCash(); + } } diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java b/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java index 73570a29..9ff57153 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java @@ -24,30 +24,20 @@ public class WithdrawController { private final WithdrawService withdrawService; - private final MemberService memberService; private final Rq rq; @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") @GetMapping("/withDraw") - public String showApply(Model model) { - Member member = rq.getRollMember(); - if(!member.getRole().getValue().equals("BRAND_ADMIN")){ - return rq.historyBack("브랜드 관리자만 접근할 수 있습니다."); - } - model.addAttribute("actorRestCash", memberService.getRestCash(member)); + public String showApplyForm(Model model) { + model.addAttribute("actorRestCash", withdrawService.showRestCash(rq.getBrandMember())); return "trendpick/admin/withDraw"; } @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") @PostMapping("/withDraw") public String apply(@Valid WithDrawApplyForm withDrawApplyForm) { - RsData rsData = withdrawService.apply( - withDrawApplyForm.getBankName(), - withDrawApplyForm.getBankAccountNo(), - withDrawApplyForm.getPrice(), - rq.getBrandMember() - ); + withdrawService.apply(withDrawApplyForm, rq.getBrandMember()); - return rq.redirectWithMsg("/trendpick/admin/withDrawList","출금 신청이 완료되었습니다."); + return rq.redirectWithMsg("/trendpick/admin/withDrawList", "출금 신청이 완료되었습니다."); } } From 50abe283bf92db45e5c2c32e2391a074adec71f3 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:23:18 +0900 Subject: [PATCH 11/46] =?UTF-8?q?refactor:=20Rebate=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20(=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD,?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=EA=B0=84=EC=86=8C=ED=99=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/rebate/service/RebateService.java | 11 +- .../service/impl/RebateServiceImpl.java | 104 ++++++++++-------- .../trendpick_pro/global/util/rq/Rq.java | 10 +- .../trendpick/admin/rebateOrderItemList.html | 4 +- 4 files changed, 63 insertions(+), 66 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/rebate/service/RebateService.java b/src/main/java/project/trendpick_pro/domain/rebate/service/RebateService.java index c93b224f..9559b2f2 100644 --- a/src/main/java/project/trendpick_pro/domain/rebate/service/RebateService.java +++ b/src/main/java/project/trendpick_pro/domain/rebate/service/RebateService.java @@ -7,12 +7,7 @@ import java.util.List; public interface RebateService { - RsData makeDate(String brandName,String yearMonth); - - void makeRebateOrderItem(RebateOrderItem item); - - RebateOrderItem toRebateOrderItem(OrderItem orderItem); - - List findRebateOrderItemsByCreatedDateIn(String brandName,String yearMonth); - RsData rebate(long orderItemId); + RsData makeData(String brandName,String yearMonth); + List findRebateDataByCurrentYearMonth(String brandName,String yearMonth); + RsData rebate(Long orderItemId); } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/rebate/service/impl/RebateServiceImpl.java b/src/main/java/project/trendpick_pro/domain/rebate/service/impl/RebateServiceImpl.java index 33b4d147..6f0f9f2f 100644 --- a/src/main/java/project/trendpick_pro/domain/rebate/service/impl/RebateServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/rebate/service/impl/RebateServiceImpl.java @@ -4,37 +4,40 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import project.trendpick_pro.domain.cash.entity.CashLog; -import project.trendpick_pro.domain.member.service.MemberService; +import project.trendpick_pro.domain.cash.service.CashService; import project.trendpick_pro.domain.orders.entity.OrderItem; import project.trendpick_pro.domain.orders.service.OrderService; import project.trendpick_pro.domain.rebate.entity.RebateOrderItem; import project.trendpick_pro.domain.rebate.repository.RebateOrderItemRepository; import project.trendpick_pro.domain.rebate.service.RebateService; +import project.trendpick_pro.domain.store.service.StoreService; import project.trendpick_pro.global.util.rsData.RsData; import project.trendpick_pro.global.util.Ut; - import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class RebateServiceImpl implements RebateService { - private final OrderService orderService; - private final MemberService memberService; private final RebateOrderItemRepository rebateOrderItemRepository; + private final OrderService orderService; + private final CashService cashService; + private final StoreService storeService; @Transactional - public RsData makeDate(String brandName, String yearMonth) { + @Override + public RsData makeData(String brandName, String yearMonth) { String fromDateStr = yearMonth + "-01 00:00:00.000000"; String toDateStr = yearMonth + "-%02d 23:59:59.999999".formatted(Ut.date.getEndDayOf(yearMonth)); List orderItems = orderService.findAllByCreatedDateBetweenOrderByIdAsc( Ut.date.parse(fromDateStr), Ut.date.parse(toDateStr) ); - if(orderItems.isEmpty()){ + if(orderItems.isEmpty()) return RsData.of("F-1","정산할 주문내역이 없습니다."); - } + List brandOrderItems=new ArrayList<>(); for(OrderItem item: orderItems) { if (item.getProduct().getProductOption().getBrand().getName().equals(brandName)) { @@ -47,62 +50,69 @@ public RsData makeDate(String brandName, String yearMonth) { .map(this::toRebateOrderItem) .toList(); - rebateOrderItems.forEach(this::makeRebateOrderItem); + rebateOrderItems.forEach(this::updateOrCreateRebateData); return RsData.of("S-1", "정산데이터가 성공적으로 생성되었습니다."); } @Transactional - public void makeRebateOrderItem(RebateOrderItem item) { - RebateOrderItem oldRebateOrderItem = rebateOrderItemRepository.findByOrderItemId(item.getOrderItem().getId()).orElse(null); - if (oldRebateOrderItem != null) { - if (oldRebateOrderItem.isRebateDone()) { - return; - } - oldRebateOrderItem.updateWith(item); - rebateOrderItemRepository.save(oldRebateOrderItem); - } else { - rebateOrderItemRepository.save(item); - } - } - @Transactional - public RebateOrderItem toRebateOrderItem(OrderItem orderItem) { - return new RebateOrderItem(orderItem); + @Override + public RsData rebate(Long orderItemId) { + RebateOrderItem rebateOrderItem = rebateOrderItemRepository.findByOrderItemId(orderItemId).orElse(null); + + RsData validateResult = validateAvailableRebate(rebateOrderItem); + if (validateResult.isFail()) return validateResult; + + //캐시로그 생성 + CashLog cashLog = cashService.addCashLog(rebateOrderItem); + //스토어 정산캐시 추가 + storeService.addRebateCash(rebateOrderItem.getSellerName(), rebateOrderItem.calculateRebatePrice()); + //정산완료 + rebateOrderItem.setRebateDone(cashLog); + return RsData.of( + "S-1", + "주문품목번호 %d번에 대해서 정산을 완료하였습니다.".formatted(rebateOrderItem.getOrderItem().getId()) + ); } - @Transactional(readOnly = true) - public List findRebateOrderItemsByCreatedDateIn(String brandName,String yearMonth) { + @Override + public List findRebateDataByCurrentYearMonth(String brandName,String yearMonth) { int monthEndDay = Ut.date.getEndDayOf(yearMonth); - String fromDateStr = yearMonth + "-01 00:00:00.000000"; String toDateStr = yearMonth + "-%02d 23:59:59.999999".formatted(monthEndDay); - LocalDateTime fromDate = Ut.date.parse(fromDateStr); + LocalDateTime fromDate = Ut.date.parse(fromDateStr); //yyyy-MM-dd HH:mm:ss.SSSSSS 패턴으로 만들기 LocalDateTime toDate = Ut.date.parse(toDateStr); - return rebateOrderItemRepository.findAllByCreatedDateBetweenAndSellerNameOrderByIdAsc(fromDate, toDate,brandName); + return rebateOrderItemRepository.findAllByCreatedDateBetweenAndSellerNameOrderByIdAsc(fromDate, toDate, brandName); } - @Transactional - public RsData rebate(long orderItemId) { - RebateOrderItem rebateOrderItem = rebateOrderItemRepository.findByOrderItemId(orderItemId).get(); - - if (!rebateOrderItem.isRebateAvailable()) { - return RsData.of("F-1", "정산을 할 수 없는 상태입니다."); - } - int calculateRebatePrice = rebateOrderItem.calculateRebatePrice(); + private static RsData validateAvailableRebate(RebateOrderItem rebateOrderItem) { + if(rebateOrderItem == null) + return RsData.of("F-2", "존재하지 않는 정산 데이터입니다."); + if (!rebateOrderItem.checkAlreadyRebate()) + return RsData.of("F-1", "이미 정산된 데이터입니다."); + if(!rebateOrderItem.getOrder().isCompletedPurchaseDecision()) + return RsData.of("F-3", "구매결정이 완료되지 않은 데이터입니다."); + return RsData.success(); + } - CashLog cashLog = memberService.addCash( - rebateOrderItem.getSellerName(), - calculateRebatePrice, - rebateOrderItem.getSeller(), - CashLog.EvenType.브랜드정산__예치금 - ).getData().getCashLog(); + private void updateOrCreateRebateData(RebateOrderItem item) { + //orderItem의 id값으로 조회해봐서 이미 정산데이터로 생성되어 있다면, 업데이트 처리 + RebateOrderItem oldRebateOrderItem = rebateOrderItemRepository.findByOrderItemId(item.getOrderItem().getId()).orElse(null); + if (oldRebateOrderItem != null) { + if (oldRebateOrderItem.isRebateDone()) { + return; + } + oldRebateOrderItem.updateWith(item); + rebateOrderItemRepository.save(oldRebateOrderItem); + } else { + rebateOrderItemRepository.save(item); + } + } - rebateOrderItem.setRebateDone(cashLog.getId()); - return RsData.of( - "S-1", - "주문품목번호 %d번에 대해서 정산을 완료하였습니다.".formatted(rebateOrderItem.getOrderItem().getId()) - ); + private RebateOrderItem toRebateOrderItem(OrderItem orderItem) { + return new RebateOrderItem(orderItem); } + } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/global/util/rq/Rq.java b/src/main/java/project/trendpick_pro/global/util/rq/Rq.java index 855c3617..396fbf98 100644 --- a/src/main/java/project/trendpick_pro/global/util/rq/Rq.java +++ b/src/main/java/project/trendpick_pro/global/util/rq/Rq.java @@ -79,15 +79,7 @@ public Boolean admin() { return getLogin().getRole().equals(MemberRoleType.ADMIN); } public Member getRollMember(){ - Member member=getLogin(); - if(member.getRole().equals(MemberRoleType.MEMBER)){ - return member; - } else if(member.getRole().equals(MemberRoleType.BRAND_ADMIN)){ - return member; - } else if(member.getRole().equals(MemberRoleType.ADMIN)){ - return member; - } - throw new MemberNotMatchException("허용된 권한이 아닙니다."); + return getLogin(); } public Member getBrandMember() { Member member = getLogin(); diff --git a/src/main/resources/templates/trendpick/admin/rebateOrderItemList.html b/src/main/resources/templates/trendpick/admin/rebateOrderItemList.html index 26519453..38103ee6 100644 --- a/src/main/resources/templates/trendpick/admin/rebateOrderItemList.html +++ b/src/main/resources/templates/trendpick/admin/rebateOrderItemList.html @@ -54,7 +54,7 @@

- @@ -65,7 +65,7 @@

- 정산 From f5667346ddf34aeb65cb667da3ae46556572af7a Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:25:44 +0900 Subject: [PATCH 12/46] =?UTF-8?q?refactor:=20CashLog=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EA=B0=84=EC=86=8C=ED=99=94=20(=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C,=20?= =?UTF-8?q?=EC=BA=A1=EC=8A=90=ED=99=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/cash/entity/CashLog.java | 24 ++++- .../domain/cash/entity/dto/CashResponse.java | 2 - .../domain/cash/service/CashService.java | 5 +- .../cash/service/impl/CashServiceImpl.java | 31 +++--- .../service/impl/CouponCardServiceImpl.java | 11 +-- .../controller/AdmRebateController.java | 97 +++++++++---------- .../domain/rebate/entity/RebateOrderItem.java | 26 +++-- 7 files changed, 106 insertions(+), 90 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/cash/entity/CashLog.java b/src/main/java/project/trendpick_pro/domain/cash/entity/CashLog.java index 07ba24a4..b2d09f48 100644 --- a/src/main/java/project/trendpick_pro/domain/cash/entity/CashLog.java +++ b/src/main/java/project/trendpick_pro/domain/cash/entity/CashLog.java @@ -6,6 +6,8 @@ import lombok.ToString; import lombok.experimental.SuperBuilder; import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.rebate.entity.RebateOrderItem; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; import static jakarta.persistence.FetchType.LAZY; @@ -14,7 +16,7 @@ @NoArgsConstructor @SuperBuilder @ToString(callSuper = true) -public class CashLog { +public class CashLog { //돈의 흐름을 기록하기 위한 엔티티 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "cash_log_id") @@ -31,12 +33,24 @@ public class CashLog { @Enumerated(EnumType.STRING) private EvenType eventType; - - public CashLog(Long id){ - this.id=id; - } public enum EvenType { 출금__통장입금, 브랜드정산__예치금; } + + static public CashLog of(WithdrawApply withdrawApply){ + return CashLog.builder() + .price(withdrawApply.getPrice() * -1) + .relTypeCode(withdrawApply.getBankName()) + .eventType(EvenType.출금__통장입금) + .build(); + } + + static public CashLog of(RebateOrderItem rebateData){ + return CashLog.builder() + .price(rebateData.calculateRebatePrice()) + .relTypeCode(rebateData.getSellerName()) + .eventType(EvenType.브랜드정산__예치금) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/cash/entity/dto/CashResponse.java b/src/main/java/project/trendpick_pro/domain/cash/entity/dto/CashResponse.java index 7eed5f23..c6903c1d 100644 --- a/src/main/java/project/trendpick_pro/domain/cash/entity/dto/CashResponse.java +++ b/src/main/java/project/trendpick_pro/domain/cash/entity/dto/CashResponse.java @@ -7,7 +7,5 @@ @Getter @AllArgsConstructor public class CashResponse { - CashLog cashLog; - long newRestCash; } diff --git a/src/main/java/project/trendpick_pro/domain/cash/service/CashService.java b/src/main/java/project/trendpick_pro/domain/cash/service/CashService.java index 62ed08af..732005f8 100644 --- a/src/main/java/project/trendpick_pro/domain/cash/service/CashService.java +++ b/src/main/java/project/trendpick_pro/domain/cash/service/CashService.java @@ -3,9 +3,12 @@ import project.trendpick_pro.domain.cash.entity.CashLog; import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.rebate.entity.RebateOrderItem; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; public interface CashService { - CashLog addCash(Member member, long price, String relTypeCode,Long relId, CashLog.EvenType eventType); + CashLog addCashLog(WithdrawApply withdrawApply); + CashLog addCashLog(RebateOrderItem rebateOrderItem); } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/cash/service/impl/CashServiceImpl.java b/src/main/java/project/trendpick_pro/domain/cash/service/impl/CashServiceImpl.java index 659744a6..1adfc5a1 100644 --- a/src/main/java/project/trendpick_pro/domain/cash/service/impl/CashServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/cash/service/impl/CashServiceImpl.java @@ -2,26 +2,35 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import project.trendpick_pro.domain.brand.entity.Brand; +import project.trendpick_pro.domain.brand.service.BrandService; import project.trendpick_pro.domain.cash.entity.CashLog; import project.trendpick_pro.domain.cash.repository.CashLogRepository; import project.trendpick_pro.domain.cash.service.CashService; import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.member.service.MemberService; +import project.trendpick_pro.domain.rebate.entity.RebateOrderItem; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; + @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class CashServiceImpl implements CashService { private final CashLogRepository cashLogRepository; + @Transactional + @Override + public CashLog addCashLog(WithdrawApply withdrawApply) { + CashLog cashLog = cashLogRepository.save(CashLog.of(withdrawApply)); + return cashLog; + } - public CashLog addCash(Member member, long price, String relTypeCode, Long relId, CashLog.EvenType eventType) { - CashLog cashLog = CashLog.builder() - .member(member) - .price(price) - .relTypeCode(relTypeCode) - .relId(relId) - .eventType(eventType) - .build(); - - cashLogRepository.save(cashLog); - + @Transactional + @Override + public CashLog addCashLog(RebateOrderItem rebateOrderItem) { + CashLog cashLog = cashLogRepository.save(CashLog.of(rebateOrderItem)); return cashLog; } + + } diff --git a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java index f603246f..cdf69652 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java @@ -35,10 +35,9 @@ public RsData issue(Member member, Long couponId, LocalDateTime dateTime) { () -> new CouponNotFoundException("존재하지 않는 쿠폰입니다.")); int count = couponCardRepository.countByCouponIdAndMemberId(couponId, member.getId()); - RsData of = validateCouponCard(count, coupon); - if (of != null) { - return of; - } + RsData validateResult = validateCouponCard(count, coupon); + if (validateResult != null) + return validateResult; CouponCard savedCouponCard = settingCouponCard(member, dateTime, coupon); return RsData.of("S-1", coupon.getName() + " 쿠폰이 발급되었습니다."); @@ -50,9 +49,9 @@ public RsData apply(Long couponCardId, Long orderItemId) { OrderItem orderItem = orderItemRepository.findById(orderItemId).orElseThrow( () -> new OrderItemNotFoundException("주문되지 않은 상품입니다.")); CouponCard couponCard = couponCardRepository.findById(couponCardId).orElseThrow( - () -> new CouponNotFoundException("존재하지 않은 쿠폰입니다.")); + () -> new CouponNotFoundException("존재하지 않는 쿠폰입니다.")); if (!couponCard.validate(orderItem, LocalDateTime.now())) - return RsData.of("F-1", "해당 주문상품에 적용된 쿠폰이 없습니다."); + return RsData.of("F-1", "해당 주문상품에 해당 쿠폰을 적용할 수 없습니다."); couponCard.use(orderItem, LocalDateTime.now()); return RsData.of("S-1", "쿠폰이 적용되었습니다."); } diff --git a/src/main/java/project/trendpick_pro/domain/rebate/controller/AdmRebateController.java b/src/main/java/project/trendpick_pro/domain/rebate/controller/AdmRebateController.java index 2e25d1ba..bd8d1588 100644 --- a/src/main/java/project/trendpick_pro/domain/rebate/controller/AdmRebateController.java +++ b/src/main/java/project/trendpick_pro/domain/rebate/controller/AdmRebateController.java @@ -23,65 +23,60 @@ @RequestMapping("/trendpick/admin") @RequiredArgsConstructor public class AdmRebateController { + private final RebateService rebateService; + private final Rq rq; - private final RebateService rebateService; - private final Rq rq; + @GetMapping("/makeData") + @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") //브랜드 관리자만 접근 가능 + public String showMakeData() { + return "trendpick/admin/makeData"; + } - @GetMapping("/makeData") - @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") - public String showMakeData() { - if(!rq.getRollMember().getRole().getValue().equals("BRAND_ADMIN")){ - return rq.historyBack("브랜드 관리자만 접근할 수 있습니다."); - } return "trendpick/admin/makeData"; + @PostMapping("/makeData") + @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") + public String makeData(String yearMonth) { + RsData makeDateRsData = rebateService.makeData(rq.getBrandName(), yearMonth); + if (makeDateRsData.isFail()) { + return rq.historyBack("정산할 데이터가 없습니다."); } + return rq.redirectWithMsg("/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth, makeDateRsData); + } - @PostMapping("/makeData") - @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") - public String makeData(String yearMonth) { - RsData makeDateRsData = rebateService.makeDate(rq.getBrandName(), yearMonth); - if(makeDateRsData.isFail()){ - return rq.historyBack("정산할 데이터가 없습니다."); - } return rq.redirectWithMsg("/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth, makeDateRsData); - } + @GetMapping("/rebateOrderItemList") + @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") + public String showRebateOrderItemList(String yearMonth, Model model) { + if (!StringUtils.hasText(yearMonth)) + yearMonth = Ut.date.getCurrentYearMonth(); - @GetMapping("/rebateOrderItemList") - @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") - public String showRebateOrderItemList(String yearMonth, Model model) { - if(!rq.getRollMember().getRole().getValue().equals("BRAND_ADMIN")){ - return rq.historyBack("브랜드 관리자만 접근할 수 있습니다."); - } - if (!StringUtils.hasText(yearMonth)) { - yearMonth = Ut.date.getCurrentYearMonth(); - } - List items = rebateService.findRebateOrderItemsByCreatedDateIn(rq.getBrandName(),yearMonth); + List items = rebateService.findRebateDataByCurrentYearMonth(rq.getBrandName(), yearMonth); - model.addAttribute("yearMonth", yearMonth); - model.addAttribute("items", items); - return "trendpick/admin/rebateOrderItemList"; - } + model.addAttribute("yearMonth", yearMonth); + model.addAttribute("items", items); + return "trendpick/admin/rebateOrderItemList"; + } - @PostMapping("/rebateOne/{orderItemId}") - @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") - public String rebateOne(@PathVariable long orderItemId, HttpServletRequest req) { - RsData rebateRsData = rebateService.rebate(orderItemId); - if(rebateRsData.isFail()){ - return rq.historyBack("정산할 수 없는 상태입니다."); - } - String yearMonth = Ut.url.getQueryParamValue(req.getHeader("Referer"), "yearMonth", ""); - return rq.redirectWithMsg("/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth, rebateRsData); + @PostMapping("/rebateOne/{orderItemId}") + @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") + public String rebateOne(@PathVariable long orderItemId, HttpServletRequest req) { + RsData result = rebateService.rebate(orderItemId); + if (result.isFail()) { + return rq.historyBack(result); } + String yearMonth = Ut.url.getQueryParamValue(req.getHeader("Referer"), "yearMonth", ""); + return rq.redirectWithMsg("/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth, result); + } - @PostMapping("/rebate") - @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") - public String rebate(String ids, HttpServletRequest req) { - String[] idsArr = ids.split(","); - Arrays.stream(idsArr) - .mapToLong(Long::parseLong) - .forEach(rebateService::rebate); - String yearMonth = Ut.url.getQueryParamValue(req.getHeader("Referer"), "yearMonth", ""); + @PostMapping("/rebate") + @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") + public String rebate(String ids, HttpServletRequest req) { + String[] idsArr = ids.split(","); + Arrays.stream(idsArr) + .mapToLong(Long::parseLong) + .forEach(rebateService::rebate); + String yearMonth = Ut.url.getQueryParamValue(req.getHeader("Referer"), "yearMonth", ""); - String redirect = "redirect:/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth; - redirect += "&msg=" + Ut.url.encode("%d건의 정산품목을 정산처리하였습니다.".formatted(idsArr.length)); - return redirect; - } + String redirect = "redirect:/trendpick/admin/rebateOrderItemList?yearMonth=" + yearMonth; + redirect += "&msg=" + Ut.url.encode("%d건의 정산품목을 정산처리하였습니다.".formatted(idsArr.length)); + return redirect; + } } diff --git a/src/main/java/project/trendpick_pro/domain/rebate/entity/RebateOrderItem.java b/src/main/java/project/trendpick_pro/domain/rebate/entity/RebateOrderItem.java index 082cf9db..14811cc1 100644 --- a/src/main/java/project/trendpick_pro/domain/rebate/entity/RebateOrderItem.java +++ b/src/main/java/project/trendpick_pro/domain/rebate/entity/RebateOrderItem.java @@ -43,15 +43,16 @@ public class RebateOrderItem extends BaseTimeEntity { @OneToOne(fetch = LAZY) @JoinColumn(name = "coupon_card_id") private CouponCard couponCard; - @Column(name = "order_price", nullable = false) - private int orderPrice; - @Column(name = "total_price") - private int totalPrice; - + private int totalPrice; //전체금액 (할인제외) + @Column(name = "order_price", nullable = false) + private int orderPrice; //주문금액 (할인 계산된 금액) @Column(name = "discount_price") - private int discountPrice; + private int discountPrice; //할인 받은 금액 + // 상품 + @Column(name = "product_subject", nullable = false) + private String productSubject; @Column(name = "size", nullable = false) private String size; @@ -60,14 +61,11 @@ public class RebateOrderItem extends BaseTimeEntity { @Column(name = "count", nullable = false) private int quantity; - - @ManyToOne(fetch = LAZY) + @OneToOne(fetch = LAZY) @ToString.Exclude @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private CashLog rebateCashLog; // 정산에 관련된 환급지급내역 private LocalDateTime rebateDate; - // 상품 - private String productSubject; // 주문품목 private LocalDateTime orderItemCreateDate; @@ -113,18 +111,18 @@ public RebateOrderItem(OrderItem orderItem) { } public int calculateRebatePrice() { - return (totalPrice*quantity) - (int)(totalPrice * 0.05); // 정산금액 수수료 0.05% 제외하고 계산 + return (totalPrice*quantity - discountPrice) - (int)(totalPrice * 0.05); // 정산금액 수수료 5%(임의) 제외하고 계산 } - public boolean isRebateAvailable() { + public boolean checkAlreadyRebate() { if (rebateDate != null) { return false; } return true; } - public void setRebateDone(Long cashLogId) { + public void setRebateDone(CashLog cashLog) { rebateDate = LocalDateTime.now(); - this.rebateCashLog = new CashLog(cashLogId); + this.rebateCashLog = cashLog; } public boolean isRebateDone() { From 8c7d2cc201970af62ef2d183f0efd00cf791e50e Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:27:40 +0900 Subject: [PATCH 13/46] =?UTF-8?q?fix:=20cash=EA=B0=80=20=EC=A0=9C=EB=8C=80?= =?UTF-8?q?=EB=A1=9C=20=EC=83=9D=EC=84=B1=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 9 ++--- .../service/impl/MemberServiceImpl.java | 33 +++++++------------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/member/service/MemberService.java b/src/main/java/project/trendpick_pro/domain/member/service/MemberService.java index c4b712f4..69e26d6a 100644 --- a/src/main/java/project/trendpick_pro/domain/member/service/MemberService.java +++ b/src/main/java/project/trendpick_pro/domain/member/service/MemberService.java @@ -1,14 +1,11 @@ package project.trendpick_pro.domain.member.service; -import project.trendpick_pro.domain.brand.entity.Brand; -import project.trendpick_pro.domain.cash.entity.CashLog; -import project.trendpick_pro.domain.cash.entity.dto.CashResponse; import project.trendpick_pro.domain.member.entity.Member; import project.trendpick_pro.domain.member.entity.dto.response.MemberInfoResponse; import project.trendpick_pro.domain.member.entity.form.JoinForm; import project.trendpick_pro.domain.tags.tag.entity.dto.request.TagRequest; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; import project.trendpick_pro.global.util.rsData.RsData; - import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -19,9 +16,9 @@ public interface MemberService { void modifyTag(Member member, TagRequest tagRequest); RsData modifyAddress(Member member, String address); Member findById(Long id); - Member findByBrandMember(String name); + Member findBrandMember(String name); Optional findByEmail(String username); void updateRecentlyAccessDate(Member member, LocalDateTime dateTime); - RsData addCash(String brand, long price, Brand relEntity, CashLog.EvenType eventType); long getRestCash(Member member); + void completeWithdraw(WithdrawApply withdrawApply); } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/member/service/impl/MemberServiceImpl.java b/src/main/java/project/trendpick_pro/domain/member/service/impl/MemberServiceImpl.java index 68219913..5db30f05 100644 --- a/src/main/java/project/trendpick_pro/domain/member/service/impl/MemberServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/member/service/impl/MemberServiceImpl.java @@ -5,11 +5,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import project.trendpick_pro.domain.brand.entity.Brand; import project.trendpick_pro.domain.brand.service.BrandService; -import project.trendpick_pro.domain.cash.entity.CashLog; -import project.trendpick_pro.domain.cash.entity.dto.CashResponse; -import project.trendpick_pro.domain.cash.service.CashService; import project.trendpick_pro.domain.member.entity.Member; import project.trendpick_pro.domain.member.entity.MemberRoleType; import project.trendpick_pro.domain.member.entity.dto.response.MemberInfoResponse; @@ -22,6 +18,7 @@ import project.trendpick_pro.domain.store.service.StoreService; import project.trendpick_pro.domain.tags.favoritetag.entity.FavoriteTag; import project.trendpick_pro.domain.tags.tag.entity.dto.request.TagRequest; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; import project.trendpick_pro.global.util.rsData.RsData; import java.time.LocalDateTime; @@ -38,7 +35,6 @@ public class MemberServiceImpl implements MemberService { private final PasswordEncoder passwordEncoder; private final RecommendService recommendService; private final StoreService storeService; - private final CashService cashService; private final BrandService brandService; @Transactional @@ -89,7 +85,7 @@ public Member findById(Long id) { } @Override - public Member findByBrandMember(String name){ + public Member findBrandMember(String name){ return memberRepository.findByBrand(name); } @@ -104,24 +100,9 @@ public void updateRecentlyAccessDate(Member member, LocalDateTime dateTime){ member.updateRecentlyAccessDate(dateTime); } - @Transactional - @Override - public RsData addCash(String brand, long price, Brand relEntity, CashLog.EvenType eventType) { - Member member=findByBrandMember(brand); - if(!member.getBrand().equals(brand)){ - return RsData.of("F-1","해당 브랜드와 관리자가 일치하지 않습니다."); - } - CashLog cashLog = cashService.addCash(member, price, relEntity.getName(),relEntity.getId(), eventType); - - long newRestCash = getRestCash(member) + cashLog.getPrice(); - member.connectCash(newRestCash); - - return RsData.of("S-1", "성공", new CashResponse(cashLog, newRestCash)); - } - @Override public long getRestCash(Member member) { - return memberRepository.findById(member.getId()).get().getRestCash(); + return member.getRestCash(); } private void checkingMemberType(Member member) { @@ -159,4 +140,12 @@ private Set createFavoriteTags(List tagList) { .map(FavoriteTag::new) .collect(Collectors.toSet()); } + + @Transactional + @Override + public void completeWithdraw(WithdrawApply withdrawApply) { + Member member = withdrawApply.getApplicant(); + long newRestCash = member.getRestCash() - withdrawApply.getPrice(); + member.connectCash(newRestCash); + } } \ No newline at end of file From 0156dd644dde16536e5ef5bdeb36f038b20de717 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:29:10 +0900 Subject: [PATCH 14/46] =?UTF-8?q?=20feat:=20=EC=A0=95=EC=82=B0=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=A3=BC=EB=AC=B8=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=ED=95=A8=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/trendpick_pro/domain/orders/entity/Order.java | 5 +++++ .../domain/orders/service/impl/OrderServiceImpl.java | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java b/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java index 996f7699..f7d5144d 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java +++ b/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java @@ -129,4 +129,9 @@ private void addOrderItem(OrderItem orderItem) { orderItems.add(orderItem); orderItem.connectOrder(this); } + + //구매결정 완료된건지 (환불불가, 취소불가) + public boolean isCompletedPurchaseDecision(){ + return this.getDeliveryState().equals("배송완료") && this.getOrderState().equals("결제완료"); + } } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java index 613c6f14..2cdf75bc 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java @@ -1,13 +1,11 @@ package project.trendpick_pro.domain.orders.service.impl; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; -import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import project.trendpick_pro.domain.cart.entity.CartItem; @@ -21,7 +19,6 @@ import project.trendpick_pro.domain.orders.entity.OrderStatus; import project.trendpick_pro.domain.orders.entity.dto.request.CartToOrderRequest; import project.trendpick_pro.domain.orders.entity.dto.request.OrderSearchCond; -import project.trendpick_pro.domain.orders.entity.dto.request.OrderStateResponse; import project.trendpick_pro.domain.orders.entity.dto.response.OrderDetailResponse; import project.trendpick_pro.domain.orders.entity.dto.response.OrderResponse; import project.trendpick_pro.domain.orders.exception.OrderNotFoundException; @@ -44,7 +41,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.UUID; import java.util.stream.Collectors; @Transactional(readOnly = true) @@ -84,11 +80,11 @@ public RsData cartToOrder(Member member, CartToOrderRequest request) { } @Transactional - public RsData productToOrder(Member member, Long id, int quantity, String size, String color) { + public RsData productToOrder(Member member, Long productId, int quantity, String size, String color) { try { Order saveOrder = orderRepository.save( Order.createOrder(member, new Delivery(member.getAddress()), - List.of(OrderItem.of(productService.findById(id), quantity, size, color)) + List.of(OrderItem.of(productService.findById(productId), quantity, size, color)) ) ); OutboxMessage message = createOutboxMessage(saveOrder); From 5821a780efe9bb7d11b8ebe1790f66afe3458fb0 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:30:28 +0900 Subject: [PATCH 15/46] =?UTF-8?q?refacotr:=20brand=5Fadmin=20/=20admin=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../domain/delivery/entity/Delivery.java | 2 +- src/main/resources/application-dev.yml | 8 ++--- .../trendpick/usr/layout/layout.html | 29 +++++++++++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b3f1be53..22a87618 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +docker-compose.yml ### STS ### .apt_generated diff --git a/src/main/java/project/trendpick_pro/domain/delivery/entity/Delivery.java b/src/main/java/project/trendpick_pro/domain/delivery/entity/Delivery.java index cae6b6e4..32341eb1 100644 --- a/src/main/java/project/trendpick_pro/domain/delivery/entity/Delivery.java +++ b/src/main/java/project/trendpick_pro/domain/delivery/entity/Delivery.java @@ -26,7 +26,7 @@ public class Delivery extends BaseTimeEntity { public Delivery(String address){ this.address = address; - state = DeliveryState.READY; + state = DeliveryState.COMPLETED; //원활한 테스트를 위해서 배송 완료로 임시 설정 } public void updateStatus(String status){ diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index e7110b0c..61277fca 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,9 +1,9 @@ spring: datasource: - driver-class-name: org.h2.Driver - url: jdbc:h2:mem:test; - username: sa - password: + driver-class-name: ${db.driver} + url: ${db.url} + username: ${db.username} + password: ${db.password} jpa: hibernate: ddl-auto: create diff --git a/src/main/resources/templates/trendpick/usr/layout/layout.html b/src/main/resources/templates/trendpick/usr/layout/layout.html index f4b6d59c..689e56e0 100644 --- a/src/main/resources/templates/trendpick/usr/layout/layout.html +++ b/src/main/resources/templates/trendpick/usr/layout/layout.html @@ -145,12 +145,12 @@

TrendPick

  • - 받을 수 있는 쿠폰목록 + 쿠폰목록
  • - From 62f12be69fef43ad6879af14fd881a84d29a44ab Mon Sep 17 00:00:00 2001 From: jooooonj Date: Sun, 20 Aug 2023 17:58:15 +0900 Subject: [PATCH 16/46] =?UTF-8?q?fix:=20git=20merge=20=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=BD=94=EB=93=9C=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EA=B1=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/service/impl/CouponCardServiceImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java index af00b837..85a3059f 100644 --- a/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/coupon/service/impl/CouponCardServiceImpl.java @@ -35,8 +35,8 @@ public RsData issue(Member member, Long couponId, LocalDateTime dateTime) { () -> new CouponNotFoundException("존재하지 않는 쿠폰입니다.")); int count = couponCardRepository.countByCouponIdAndMemberId(couponId, member.getId()); - RsData validateResult = validateCouponCard(count, coupon); - if (validateResult != null) + RsData validateResult = validateCouponCard(count, coupon, dateTime); + if (validateResult.isFail()) return validateResult; CouponCard savedCouponCard = settingCouponCard(member, dateTime, coupon); @@ -82,14 +82,14 @@ private CouponCard settingCouponCard(Member member, LocalDateTime dateTime, Coup return savedCouponCard; } - private static RsData validateCouponCard(int count, Coupon coupon) { + private static RsData validateCouponCard(int count, Coupon coupon, LocalDateTime dateTime) { if(count > 0) return RsData.of("F-3", "이미 발급 받으신 쿠폰입니다."); if(!coupon.validateLimitCount()) return RsData.of("F-1", "수량이 모두 소진되었습니다."); - if(!coupon.validateLimitIssueDate(LocalDateTime.now())) + if(!coupon.validateLimitIssueDate(dateTime)) return RsData.of("F-2", "쿠폰 발급 가능 날짜가 지났습니다."); - return null; + return RsData.success(); } private List createCouponCardByApplyResponseList(List couponCards, OrderItem orderItem) { From 4405cc0a683accbe8de8adc841d6a1be347717ba Mon Sep 17 00:00:00 2001 From: jooooonj Date: Mon, 21 Aug 2023 17:34:51 +0900 Subject: [PATCH 17/46] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20(=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdmWithdrawController.java | 2 +- .../controller/WithdrawController.java | 5 +-- .../entity/dto/WithDrawApplyForm.java | 4 +++ .../repository/WithdrawApplyRepository.java | 3 ++ .../withdraw/service/WithdrawService.java | 2 +- .../service/impl/WithdrawServiceImpl.java | 34 +++++++++++-------- .../cart/controller/CartControllerTest.java | 1 - .../repository/CartItemRepositoryTest.java | 8 ++--- .../cart/repository/CartRepositoryTest.java | 4 +-- 9 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java b/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java index 844c691c..31971308 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/controller/AdmWithdrawController.java @@ -32,7 +32,7 @@ public String showApplyList(Model model) { if(member.getRole().getValue().equals("ADMIN")) { withdrawApplies = withdrawService.findAll(); }else{ - withdrawApplies=withdrawService.findAllWithdrawByApplicantId(member.getId()); + withdrawApplies=withdrawService.findAllWithdrawByStoreName(member.getBrand()); } model.addAttribute("withdrawApplies", withdrawApplies); return "trendpick/admin/withDrawList"; diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java b/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java index 9ff57153..b08cb9b6 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/controller/WithdrawController.java @@ -36,8 +36,9 @@ public String showApplyForm(Model model) { @PreAuthorize("hasAuthority({'BRAND_ADMIN'})") @PostMapping("/withDraw") public String apply(@Valid WithDrawApplyForm withDrawApplyForm) { - withdrawService.apply(withDrawApplyForm, rq.getBrandMember()); - + RsData result = withdrawService.apply(withDrawApplyForm, rq.getBrandMember()); + if(result.isFail()) + rq.historyBack(result); return rq.redirectWithMsg("/trendpick/admin/withDrawList", "출금 신청이 완료되었습니다."); } } diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/entity/dto/WithDrawApplyForm.java b/src/main/java/project/trendpick_pro/domain/withdraw/entity/dto/WithDrawApplyForm.java index a4f7dfb8..2f14f43f 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/entity/dto/WithDrawApplyForm.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/entity/dto/WithDrawApplyForm.java @@ -2,9 +2,13 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@AllArgsConstructor +@NoArgsConstructor public class WithDrawApplyForm { @NotBlank private String bankName; diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepository.java b/src/main/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepository.java index b4d1f9bb..3ed7348f 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepository.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepository.java @@ -11,4 +11,7 @@ public interface WithdrawApplyRepository extends JpaRepository { @Query("select w from WithdrawApply w where w.applicant.id = :id") List findAllByApplicantId(@Param("id") Long id); + + @Query("select w from WithdrawApply w where w.applicant.brand = :storeName") + List findWithdrawsByStoreName(@Param("storeName") String storeName); } diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java b/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java index 3d6e6039..60a227a4 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/service/WithdrawService.java @@ -10,7 +10,7 @@ public interface WithdrawService { RsData apply(WithDrawApplyForm withDrawApplyForm, Member applicant); List findAll(); - List findAllWithdrawByApplicantId(Long id); + List findAllWithdrawByStoreName(String storeName); RsData withdraw(Long withdrawApplyId); RsData cancelApply(Long withdrawApplyId); int showRestCash(Member brandMember); diff --git a/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java b/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java index bf69ae14..c457ec63 100644 --- a/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImpl.java @@ -30,6 +30,9 @@ public class WithdrawServiceImpl implements WithdrawService { @Transactional @Override public RsData apply(WithDrawApplyForm withDrawApplyForm, Member applicant) { + RsData validateResult = validateAvailableApply(withDrawApplyForm, applicant); + if(validateResult.isFail()) + return validateResult; WithdrawApply withdrawApply = withdrawApplyRepository.save(WithdrawApply.of(withDrawApplyForm, applicant)); return RsData.of("S-1", "출금 신청이 완료되었습니다.", withdrawApply); } @@ -40,8 +43,8 @@ public List findAll() { } @Override - public List findAllWithdrawByApplicantId(Long id){ - return withdrawApplyRepository.findAllByApplicantId(id); + public List findAllWithdrawByStoreName(String storeName){ + return withdrawApplyRepository.findWithdrawsByStoreName(storeName); } @Transactional @@ -57,10 +60,7 @@ public RsData withdraw(Long withdrawApplyId) { return RsData.of( "S-1", - "%d번 출금신청이 처리되었습니다. %s원이 출금되었습니다.".formatted(withdrawApply.getId(), Ut.nf(withdrawApply.getPrice())), - Ut.mapOf( - "cashLogId", cashLog.getId() - ) + "출금신청이 처리되었습니다. %s원이 출금되었습니다.".formatted(Ut.nf(withdrawApply.getPrice())) ); } @@ -81,12 +81,7 @@ public RsData cancelApply(Long withdrawApplyId) { ); } - @Override - public int showRestCash(Member brandMember) { - return storeService.getRestCash(brandMember.getBrand()); - } - - private static RsData validateAvailableCancel(WithdrawApply withdrawApply) { + private RsData validateAvailableCancel(WithdrawApply withdrawApply) { if (withdrawApply == null) return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); @@ -100,8 +95,19 @@ private RsData validateAvailableWithdraw(WithdrawApply withdrawApply) { return RsData.of("F-1", "출금신청 데이터를 찾을 수 없습니다."); if (withdrawApply.checkAlreadyProcessed()) return RsData.of("F-2", "이미 처리되었습니다."); - if (withdrawApply.getPrice() > withdrawApply.getApplicant().getRestCash()) - return RsData.of("F-3", "예치금이 부족합니다."); + if (withdrawApply.getPrice() > storeService.getRestCash(withdrawApply.getApplicant().getBrand())) + return RsData.of("F-3", "캐시보다 더 많은 금액을 출금할 수 없습니다."); return RsData.success(); } + + private RsData validateAvailableApply(WithDrawApplyForm withDrawApplyForm, Member applicant) { + if(withDrawApplyForm.getPrice() > storeService.getRestCash(applicant.getBrand())) + return RsData.of("F-1", "출금 요청 금액은 잔여 캐시보다 많을 수 없습니다."); + return RsData.success(); + } + + @Override + public int showRestCash(Member brandMember) { + return storeService.getRestCash(brandMember.getBrand()); + } } \ No newline at end of file diff --git a/src/test/java/project/trendpick_pro/domain/cart/controller/CartControllerTest.java b/src/test/java/project/trendpick_pro/domain/cart/controller/CartControllerTest.java index f19ffc4c..f1f1f5ef 100644 --- a/src/test/java/project/trendpick_pro/domain/cart/controller/CartControllerTest.java +++ b/src/test/java/project/trendpick_pro/domain/cart/controller/CartControllerTest.java @@ -108,7 +108,6 @@ void removeItem() throws Exception { @Test @DisplayName("장바구니에 담긴 상품의 수량을 변경하는 컨트롤러 요청") @WithMockUser(username = "testUser", roles = {"MEMBER"}) - void updateCount() throws Exception { Long cartItemId = 1L; int quantity = 10; diff --git a/src/test/java/project/trendpick_pro/domain/cart/repository/CartItemRepositoryTest.java b/src/test/java/project/trendpick_pro/domain/cart/repository/CartItemRepositoryTest.java index cd4ffcce..389fdfd9 100644 --- a/src/test/java/project/trendpick_pro/domain/cart/repository/CartItemRepositoryTest.java +++ b/src/test/java/project/trendpick_pro/domain/cart/repository/CartItemRepositoryTest.java @@ -19,13 +19,13 @@ @DataJpaTest class CartItemRepositoryTest { @Autowired - CartItemRepository cartItemRepository; + protected CartItemRepository cartItemRepository; @Autowired - ProductRepository productRepository; + protected ProductRepository productRepository; @Autowired - CartRepository cartRepository; + protected CartRepository cartRepository; @Autowired - MemberRepository memberRepository; + protected MemberRepository memberRepository; @BeforeEach void before(){ diff --git a/src/test/java/project/trendpick_pro/domain/cart/repository/CartRepositoryTest.java b/src/test/java/project/trendpick_pro/domain/cart/repository/CartRepositoryTest.java index 880a53c3..e85e3a69 100644 --- a/src/test/java/project/trendpick_pro/domain/cart/repository/CartRepositoryTest.java +++ b/src/test/java/project/trendpick_pro/domain/cart/repository/CartRepositoryTest.java @@ -13,10 +13,10 @@ class CartRepositoryTest { @Autowired - CartRepository cartRepository; + protected CartRepository cartRepository; @Autowired - MemberRepository memberRepository; + protected MemberRepository memberRepository; @Test @DisplayName("해당 회원의 장바구니를 조회한다.") From bb87bb4647ebbfe1cb8d9c705911b97175786559 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Mon, 21 Aug 2023 17:35:35 +0900 Subject: [PATCH 18/46] =?UTF-8?q?test:=20Withdraw=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WithdrawControllerTest.java | 109 ++++++++++++++++++ .../WithdrawApplyRepositoryTest.java | 55 +++++++++ 2 files changed, 164 insertions(+) create mode 100644 src/test/java/project/trendpick_pro/domain/withdraw/controller/WithdrawControllerTest.java create mode 100644 src/test/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepositoryTest.java diff --git a/src/test/java/project/trendpick_pro/domain/withdraw/controller/WithdrawControllerTest.java b/src/test/java/project/trendpick_pro/domain/withdraw/controller/WithdrawControllerTest.java new file mode 100644 index 00000000..cd245b67 --- /dev/null +++ b/src/test/java/project/trendpick_pro/domain/withdraw/controller/WithdrawControllerTest.java @@ -0,0 +1,109 @@ +package project.trendpick_pro.domain.withdraw.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import project.trendpick_pro.domain.cart.controller.CartController; +import project.trendpick_pro.domain.cart.service.CartService; +import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.member.entity.MemberRoleType; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; +import project.trendpick_pro.domain.withdraw.service.WithdrawService; +import project.trendpick_pro.global.security.SecurityConfig; +import project.trendpick_pro.global.util.rq.Rq; +import project.trendpick_pro.global.util.rsData.RsData; + +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; + +@Import(SecurityConfig.class) +@ActiveProfiles("test") +@WebMvcTest( + controllers = { + WithdrawController.class + } +) +class WithdrawControllerTest { + @Autowired + protected MockMvc mockMvc; + @Autowired + protected ObjectMapper objectMapper; + @MockBean + protected Rq rq; + @MockBean + protected WithdrawService withdrawService; + + @Test + @DisplayName("출금 신청 폼 컨트롤러") + @WithMockUser(username = "testUser", roles = {"BRAND_ADMIN"}) + void showApplyForm() throws Exception { + //given + Member member = createMember(); + int restCash = 10000; + given(rq.getBrandMember()).willReturn(member); + given(withdrawService.showRestCash(any(Member.class))).willReturn(restCash); + + //when + mockMvc.perform( + get("/trendpick/admin/withDraw") + ) + .andDo(print()) + .andExpect(view().name("trendpick/admin/withDraw")) + .andExpect(model().attributeExists("actorRestCash")) + .andExpect(model().attribute("actorRestCash", restCash)) + .andExpect(status().isOk()); + } + + @Test + @DisplayName("출금 신청 컨트롤러") + @WithMockUser(username = "testUser", roles = {"BRAND_ADMIN"}) + void apply() throws Exception { + //given + Member member = mock(Member.class); + WithDrawApplyForm withDrawApplyForm = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + given(rq.getBrandMember()).willReturn(member); + given(withdrawService.apply(any(WithDrawApplyForm.class), any(Member.class))).willReturn(RsData.success()); + + //when + mockMvc.perform( + post("/trendpick/admin/withDraw") + .param("bankName", withDrawApplyForm.getBankName()) + .param("bankAccountNo", withDrawApplyForm.getBankAccountNo()) + .param("price", String.valueOf(withDrawApplyForm.getPrice())) + ) + .andDo(print()) + .andExpect(status().isOk()); + + //then + verify(withdrawService).apply(withDrawApplyForm, member); + } + + + + private Member createMember() { + Member member = Member.builder() + .email("brand@email.com") + .password("12345") + .username("TrendPick") + .phoneNumber("010-1234-5678") + .role(MemberRoleType.BRAND_ADMIN) + .brand("Polo") + .build(); + return member; + } +} \ No newline at end of file diff --git a/src/test/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepositoryTest.java b/src/test/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepositoryTest.java new file mode 100644 index 00000000..9bc93979 --- /dev/null +++ b/src/test/java/project/trendpick_pro/domain/withdraw/repository/WithdrawApplyRepositoryTest.java @@ -0,0 +1,55 @@ +package project.trendpick_pro.domain.withdraw.repository; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import project.trendpick_pro.domain.cart.repository.CartItemRepository; +import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.member.entity.MemberRoleType; +import project.trendpick_pro.domain.member.repository.MemberRepository; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@DataJpaTest +class WithdrawApplyRepositoryTest { + @Autowired + protected WithdrawApplyRepository withdrawApplyRepository; + + @Autowired + protected MemberRepository memberRepository; + + @DisplayName("findWithdrawsByStoreName - 해당 스토어명으로 신청한 출금 신청 목록을 모두 조회한다.") + @Test + void findWithdrawsByStoreName() { + //given + Member member = memberRepository.save(Member.builder() + .email("brand@email.com") + .password("12345") + .username("TrendPick") + .phoneNumber("010-1234-5678") + .role(MemberRoleType.BRAND_ADMIN) + .brand("Polo") + .build()); + + WithDrawApplyForm withDrawApplyForm1 = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + WithDrawApplyForm withDrawApplyForm2 = new WithDrawApplyForm("우리은행", "123-456-789", 10000); + WithDrawApplyForm withDrawApplyForm3 = new WithDrawApplyForm("하나은행", "123-456-789", 10000); + withdrawApplyRepository.save(WithdrawApply.of(withDrawApplyForm1, member)); + withdrawApplyRepository.save(WithdrawApply.of(withDrawApplyForm2, member)); + withdrawApplyRepository.save(WithdrawApply.of(withDrawApplyForm3, member)); + + //when + List withdraws = withdrawApplyRepository.findWithdrawsByStoreName("Polo"); + + //then + Assertions.assertThat(withdraws.size()).isEqualTo(3); + } + + +} \ No newline at end of file From 0afa2cc24d2d9dcb441df9a1fd8b3d4d51fa480d Mon Sep 17 00:00:00 2001 From: jooooonj Date: Mon, 21 Aug 2023 17:36:03 +0900 Subject: [PATCH 19/46] =?UTF-8?q?test:=20Withdraw=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WithdrawServiceImplTest.java | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/test/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImplTest.java diff --git a/src/test/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImplTest.java b/src/test/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImplTest.java new file mode 100644 index 00000000..d04a7254 --- /dev/null +++ b/src/test/java/project/trendpick_pro/domain/withdraw/service/impl/WithdrawServiceImplTest.java @@ -0,0 +1,132 @@ +package project.trendpick_pro.domain.withdraw.service.impl; + + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import project.trendpick_pro.domain.cash.entity.CashLog; +import project.trendpick_pro.domain.cash.service.CashService; +import project.trendpick_pro.domain.member.entity.Member; +import project.trendpick_pro.domain.member.entity.MemberRoleType; +import project.trendpick_pro.domain.member.service.MemberService; +import project.trendpick_pro.domain.store.service.StoreService; +import project.trendpick_pro.domain.withdraw.entity.WithdrawApply; +import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm; +import project.trendpick_pro.domain.withdraw.repository.WithdrawApplyRepository; +import project.trendpick_pro.global.util.rsData.RsData; + +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +@ExtendWith(MockitoExtension.class) +class WithdrawServiceImplTest { + + @InjectMocks + protected WithdrawServiceImpl withdrawService; + @Mock + protected WithdrawApplyRepository withdrawApplyRepository; + @Mock + protected StoreService storeService; + @Mock + protected MemberService memberService; + @Mock + protected CashService cashService; + + @DisplayName("출금 요청 금액이 잔여 캐시보다 많으면 검증에 실패한다.") + @Test + void apply_fail() throws Exception { + //given + WithDrawApplyForm withDrawApplyForm = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + + int storeRestCash = 5000; + Member member = mock(Member.class); + given(member.getBrand()).willReturn("나이키"); + given(storeService.getRestCash(eq("나이키"))).willReturn(storeRestCash); + + //when + RsData result = withdrawService.apply(withDrawApplyForm, member); + + //then + Assertions.assertThat(result.isFail()).isTrue(); + Assertions.assertThat(result.getMsg()).isEqualTo("출금 요청 금액은 잔여 캐시보다 많을 수 없습니다."); + } + + @DisplayName("출금 요청 금액이 잔여 캐시보다 적으면 출금 요청에 성공한다.") + @Test + void apply_success() throws Exception { + //given + WithDrawApplyForm withDrawApplyForm = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + + int storeRestCash = 15000; + Member member = mock(Member.class); + given(member.getBrand()).willReturn("나이키"); + given(storeService.getRestCash(eq("나이키"))).willReturn(storeRestCash); + + //when + RsData result = withdrawService.apply(withDrawApplyForm, member); + + //then + Assertions.assertThat(result.isSuccess()).isTrue(); + Assertions.assertThat(result.getMsg()).isEqualTo("출금 신청이 완료되었습니다."); + } + + @DisplayName("이미 처리된 출금 신청은 기각된다.") + @Test + void withdraw_fail() throws Exception { + //given + WithDrawApplyForm withDrawApplyForm = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + Member member = mock(Member.class); + WithdrawApply withdrawApply = WithdrawApply.of(withDrawApplyForm, member); + withdrawApply.setApplyDone(mock(CashLog.class), "출금 완료"); + given(withdrawApplyRepository.findById(anyLong())).willReturn(Optional.of(withdrawApply)); + + //when + RsData result = withdrawService.withdraw(1L); + + //then + Assertions.assertThat(result.isFail()).isTrue(); + Assertions.assertThat(result.getMsg()).isEqualTo("이미 처리되었습니다."); + } + + @DisplayName("취소되지 않았고, 출금되지 않았고, 잔여캐시가 출금신청 캐시보다 많다면 출금에 성공한다.") + @Test + void withdraw_success() throws Exception { + //given + WithDrawApplyForm withDrawApplyForm = new WithDrawApplyForm("국민은행", "123-456-789", 10000); + Member member = createMember(); + WithdrawApply withdrawApply = WithdrawApply.of(withDrawApplyForm, member); + given(withdrawApplyRepository.findById(anyLong())).willReturn(Optional.of(withdrawApply)); + given(cashService.addCashLog(withdrawApply)).willReturn(CashLog.of(withdrawApply)); + given(storeService.getRestCash(eq("Polo"))).willReturn(20000); + + //when + RsData result = withdrawService.withdraw(1L); + + //then + Assertions.assertThat(result.isSuccess()).isTrue(); + Assertions.assertThat(result.getMsg()).isEqualTo("출금신청이 처리되었습니다. %s원이 출금되었습니다.".formatted(String.format("%,d", + withdrawApply.getPrice()))); + } + + + + private Member createMember() { + Member member = Member.builder() + .email("brand@email.com") + .password("12345") + .username("TrendPick") + .phoneNumber("010-1234-5678") + .role(MemberRoleType.BRAND_ADMIN) + .brand("Polo") + .build(); + return member; + } + +} \ No newline at end of file From f0dab4ab75c44e5938a409105b771e8ae56e41e5 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Tue, 22 Aug 2023 12:25:58 +0900 Subject: [PATCH 20/46] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EB=93=B1(=EC=B4=9D=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=EC=9A=A9)=20=ED=83=80=EC=9E=84=EB=A6=AC=ED=94=84=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/trendpick/usr/layout/layout.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/templates/trendpick/usr/layout/layout.html b/src/main/resources/templates/trendpick/usr/layout/layout.html index 689e56e0..57efd04d 100644 --- a/src/main/resources/templates/trendpick/usr/layout/layout.html +++ b/src/main/resources/templates/trendpick/usr/layout/layout.html @@ -100,7 +100,7 @@

    TrendPick

    -
    - - -
    + +