From fa671bd74ba2132a9302449c0f55e7eba06a12e8 Mon Sep 17 00:00:00 2001 From: JunYong Sun Date: Mon, 22 Jan 2024 05:06:30 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=ED=9E=88=EC=8A=A4=ED=86=A0=EB=A6=AC?= =?UTF-8?q?=20status=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../infra/kafka/AuctionEventListener.java | 13 +++++++++++++ .../service/AuctionHistoryService.java | 8 +++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0525931..b2dfcd0 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ dependencies { implementation 'software.amazon.awssdk:dynamodb:2.1.0' implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation group: 'io.github.dailyon-maven', name: 'daily-on-common', version: '0.0.9' + implementation group: 'io.github.dailyon-maven', name: 'daily-on-common', version: '0.1.0' implementation 'org.springframework.kafka:spring-kafka' implementation 'org.springframework.boot:spring-boot-starter-webflux' diff --git a/src/main/java/com/dailyon/auctionservice/infra/kafka/AuctionEventListener.java b/src/main/java/com/dailyon/auctionservice/infra/kafka/AuctionEventListener.java index 138374e..b2e5a19 100644 --- a/src/main/java/com/dailyon/auctionservice/infra/kafka/AuctionEventListener.java +++ b/src/main/java/com/dailyon/auctionservice/infra/kafka/AuctionEventListener.java @@ -4,6 +4,7 @@ import com.dailyon.auctionservice.service.AuctionHistoryService; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import dailyon.domain.order.kafka.OrderDTO; import lombok.RequiredArgsConstructor; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.support.Acknowledgment; @@ -27,4 +28,16 @@ public void cancel(String message, Acknowledgment ack) { e.printStackTrace(); } } + + @KafkaListener(topics = "approve-payment") + public void updateStatus(String message, Acknowledgment ack) { + OrderDTO orderDTO = null; + try { + orderDTO = objectMapper.readValue(message, OrderDTO.class); + auctionHistoryService.update(orderDTO.getAuctionId(), String.valueOf(orderDTO.getMemberId())); + ack.acknowledge(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/dailyon/auctionservice/service/AuctionHistoryService.java b/src/main/java/com/dailyon/auctionservice/service/AuctionHistoryService.java index 663a2e6..ecf2ce4 100644 --- a/src/main/java/com/dailyon/auctionservice/service/AuctionHistoryService.java +++ b/src/main/java/com/dailyon/auctionservice/service/AuctionHistoryService.java @@ -8,7 +8,6 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; @@ -57,4 +56,11 @@ public void delete(BiddingDTO biddingDTO) { .get(); auctionHistoryRepository.delete(auctionHistory); } + + public void update(String auctionId, String memberId) { + AuctionHistory auctionHistory = + auctionHistoryRepository.findByAuctionIdAndMemberId(auctionId, memberId).get(); + auctionHistory.setPaid(true); + auctionHistoryRepository.save(auctionHistory); + } }