Skip to content

Commit

Permalink
Merge pull request #16 from lotteon2/LF1-910-batch
Browse files Browse the repository at this point in the history
🐛 OrderType 제거 및 Feign client 요청 처리 추가
  • Loading branch information
qwerty1434 authored Jan 5, 2024
2 parents 9c3e014 + 4f699e7 commit 22ae34e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import bloomingblooms.domain.payment.KakaopayApproveRequestDto;
import bloomingblooms.domain.payment.KakaopayReadyRequestDto;
import bloomingblooms.domain.payment.KakaopayReadyResponseDto;
import bloomingblooms.domain.payment.PaymentInfoDto;
import bloomingblooms.response.CommonResponse;
import java.time.LocalDateTime;
import java.util.List;
import kr.bb.payment.service.KakaopayService;
import kr.bb.payment.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -18,6 +23,7 @@
public class OrderClientController {

private final KakaopayService kakaopayService;
private final PaymentService paymentService;

@PostMapping("/ready")
public CommonResponse<KakaopayReadyResponseDto> payReady(
Expand All @@ -31,4 +37,14 @@ public CommonResponse<LocalDateTime> payApprove(
@RequestBody KakaopayApproveRequestDto approveRequestDto) {
return CommonResponse.success(kakaopayService.kakaoPayApprove(approveRequestDto));
}

@GetMapping("/paymentInfo")
CommonResponse<List<PaymentInfoDto>> getPaymentInfo(@RequestParam List<String> orderGroupIds){
return CommonResponse.success(paymentService.getPaymentInfo(orderGroupIds));
}

@GetMapping(value = "/client/paymentDate")
CommonResponse<String> getPaymentDate(@RequestParam String orderGroupId){
return CommonResponse.success(paymentService.getPaymentDate(orderGroupId));
}
}
16 changes: 0 additions & 16 deletions src/main/java/kr/bb/payment/entity/OrderType.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/kr/bb/payment/entity/Payment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.bb.payment.entity;

import bloomingblooms.domain.notification.order.OrderType;
import bloomingblooms.domain.payment.KakaopayApproveRequestDto;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class Payment extends BaseEntity {

public static Payment toEntity(KakaopayApproveRequestDto requestDto, OrderType type) {
return Payment.builder()
.userId(Long.valueOf(requestDto.getUserId()))
.userId(requestDto.getUserId())
.orderId(requestDto.getOrderId())
.orderType(type)
.paymentCid(requestDto.getCid())
Expand Down
1 change: 0 additions & 1 deletion src/main/java/kr/bb/payment/kafka/KafkaConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@RequiredArgsConstructor
public class KafkaConsumer<T> {
private final KakaopayService kakaopayService;
private ObjectMapper objectMapper;

@KafkaListener(topics = "subscription-batch", groupId = "payment-subscription")
public void subscriptionBatch(SubscriptionBatchDtoList subscriptionBatchDtoList) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/kr/bb/payment/repository/PaymentRepository.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package kr.bb.payment.repository;

import java.util.List;
import kr.bb.payment.entity.Payment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface PaymentRepository extends JpaRepository<Payment, Long> {
Payment findByOrderId(String orderId);
@Query("select p from Payment p where p.orderId = :orderIds")
List<Payment> findAllByOrderIds(List<String> orderIds);
}
3 changes: 0 additions & 3 deletions src/main/java/kr/bb/payment/service/KakaopayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public void renewSubscription(SubscriptionBatchDtoList subscriptionBatchDtoList)
List<Long> newDeliveryIdsList = deliveryServiceClient.createDeliveryForSubscription(oldDeliveryIdsList).getData();
paymentService.saveDeliveryIds(oldDeliveryIdsMap, newDeliveryIdsList);

// SQS 로 구매자에게 주문 발생 알림


}

@NotNull
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/kr/bb/payment/service/PaymentService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package kr.bb.payment.service;

import bloomingblooms.domain.notification.order.OrderType;
import bloomingblooms.domain.payment.KakaopayApproveRequestDto;
import bloomingblooms.domain.payment.PaymentInfoDto;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.persistence.EntityNotFoundException;
import kr.bb.payment.dto.response.KakaopayApproveResponseDto;
import kr.bb.payment.entity.OrderType;
import kr.bb.payment.entity.Payment;
import kr.bb.payment.entity.Subscription;
import kr.bb.payment.entity.SubscriptionRecords;
Expand All @@ -31,7 +33,7 @@ public LocalDateTime saveSinglePaymentInfo(
KakaopayApproveRequestDto requestDto, KakaopayApproveResponseDto responseDto) {

// 정기 결제 저장
if (OrderType.ORDER_SUBSCRIPTION.toString().equals(requestDto.getOrderType())) {
if (OrderType.SUBSCRIBE.toString().equals(requestDto.getOrderType())) {
String phoneNumber = requestDto.getPhoneNumber();
Subscription subscription = SubscriptionMapper.toSubscriptionEntity(phoneNumber, responseDto);
// 배송id도 함께 저장
Expand Down Expand Up @@ -78,4 +80,28 @@ public void saveDeliveryIds(Map<Long, Long> oldDeliveryIdsMap, List<Long> newDel
subscriptionRecords.setDeliveryId(value);
}
}

@Transactional
public List<PaymentInfoDto> getPaymentInfo(List<String> orderGroupIds) {
List<Payment> allPaymentsByOrderIds = paymentRepository.findAllByOrderIds(orderGroupIds);
return allPaymentsByOrderIds.stream()
.map(
payment -> {
return PaymentInfoDto.builder()
.orderGroupId(payment.getOrderId())
.paymentActualAmount(payment.getPaymentActualAmount())
.createdAt(payment.getCreatedAt())
.build();
})
.collect(Collectors.toList());
}

@Transactional
public String getPaymentDate(String orderGroupId){
Payment payment = paymentRepository.findByOrderId(orderGroupId);
if(payment != null){
return payment.getCreatedAt().toString();
}
return "";
}
}
6 changes: 3 additions & 3 deletions src/test/java/kr/bb/payment/service/KakaopayApproveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void shutDown() {
@DirtiesContext
@Test
void kakaoPayApproveForDeliveryTest() {
KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId1", "ORDER_DELIVERY");
KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId1", "DELIVERY");

kakaopayService.kakaoPayApprove(requestDto);
mockServer.verify();
Expand All @@ -77,7 +77,7 @@ void kakaoPayApproveForDeliveryTest() {
@DirtiesContext
@Test
void kakaoPayApproveForPickupTest() {
KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId2", "ORDER_PICKUP");
KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId2", "PICKUP");

kakaopayService.kakaoPayApprove(requestDto);
mockServer.verify();
Expand Down Expand Up @@ -106,7 +106,7 @@ KakaopayApproveRequestDto creatApproveRequestDto(String orderId, String orderTyp
@Test
void kakaoPayApproveForSubscriptionTest() {
KakaopayApproveRequestDto requestDto =
creatApproveRequestDto("임시orderId2", "ORDER_SUBSCRIPTION");
creatApproveRequestDto("임시orderId2", "SUBSCRIBE");

kakaopayService.kakaoPayApprove(requestDto);
mockServer.verify();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/kr/bb/payment/service/KakaopayReadyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void kakaopayReadyForDeliveryAndPickupTest() {
KakaopayReadyRequestDto.builder()
.userId("1")
.orderId("1")
.orderType("ORDER_PICKUP")
.orderType("PICKUP")
.itemName("계절마음")
.quantity(1)
.totalAmount(52900)
Expand All @@ -47,7 +47,7 @@ void kakaopayReadyForSubscriptionTest() {
KakaopayReadyRequestDto.builder()
.userId("1")
.orderId("2")
.orderType("ORDER_DELIVERY")
.orderType("SUBSCRIBE")
.itemName("계절마음")
.quantity(1)
.totalAmount(52900)
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/kr/bb/payment/service/PaymentServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kr.bb.payment.service;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import bloomingblooms.domain.payment.PaymentInfoDto;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@Transactional
public class PaymentServiceTest {
@Autowired private PaymentService paymentService;
@Test
void getPaymentInfoTest(){
List<PaymentInfoDto> paymentInfo = paymentService.getPaymentInfo(List.of("임시주문번호"));
assertThat(paymentInfo.size()).isEqualTo(0);
}

@Test
void getPaymentDateTest(){
String paymentDate = paymentService.getPaymentDate("임시주문번호");
assertThat(paymentDate).isEmpty();
}
}

0 comments on commit 22ae34e

Please sign in to comment.