From 05a82dab471fc3a6de295ad6c00d3623c3237f56 Mon Sep 17 00:00:00 2001 From: JadeKim042386 Date: Wed, 14 Aug 2024 13:25:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A7=A4=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=20=EC=8B=9C=EC=8A=A4=ED=85=9C=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?-=20=EA=B2=BD=EB=A7=A4=EB=8A=94=20=EC=B6=94=EA=B0=80=EB=A7=8C?= =?UTF-8?q?=20=ED=95=A0=20=EC=88=98=20=EC=9E=88=EA=B8=B0=20=EB=95=8C?= =?UTF-8?q?=EB=AC=B8=EC=97=90=20=EC=B6=94=EA=B0=80=ED=95=A0=20=EB=95=8C=20?= =?UTF-8?q?=EA=B2=BD=EB=A7=A4=20=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9A=94=EC=B2=AD=20-=20=EB=82=99?= =?UTF-8?q?=EC=B0=B0=EB=90=9C=20=EA=B2=BD=EB=A7=A4=EB=A5=BC=20=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C(=EA=B5=AC=EB=A7=A4)=ED=95=A0=20=EB=95=8C=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=ED=95=9C=20=ED=9A=8C=EC=9B=90=EC=9D=98=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=EC=9D=84=20=EC=88=98=EC=A0=95=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CompletePayAuctionAlarm.java | 8 ++++-- .../auction/service/AuctionService.java | 5 ++++ .../config/properties/RecSysProperties.java | 4 ++- .../global/infra/RecSysService.java | 25 ++++++++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/alarm/service/CompletePayAuctionAlarm.java b/src/main/java/freshtrash/freshtrashbackend/domain/alarm/service/CompletePayAuctionAlarm.java index 9f140c3..0372e77 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/alarm/service/CompletePayAuctionAlarm.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/alarm/service/CompletePayAuctionAlarm.java @@ -3,6 +3,7 @@ import freshtrash.freshtrashbackend.domain.alarm.entity.constants.AlarmType; import freshtrash.freshtrashbackend.domain.alarm.service.template.BiddingHistoryAlarmTemplate; import freshtrash.freshtrashbackend.domain.auction.entity.BiddingHistory; +import freshtrash.freshtrashbackend.global.infra.RecSysService; import freshtrash.freshtrashbackend.producer.AuctionProducer; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -10,14 +11,17 @@ @Slf4j @Component public class CompletePayAuctionAlarm extends BiddingHistoryAlarmTemplate { + private final RecSysService recSysService; - public CompletePayAuctionAlarm(AuctionProducer producer) { + public CompletePayAuctionAlarm(AuctionProducer producer, RecSysService recSysService) { super(producer); + this.recSysService = recSysService; } @Override public void update(BiddingHistory biddingHistory) { - log.debug("결제 여부를 true로 업데이트"); + log.debug("프로필 업데이트 후 결제 여부를 true로 업데이트"); + recSysService.purchaseAuction(biddingHistory.getAuctionId(), biddingHistory.getMemberId()); biddingHistory.setPay(true); } diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java b/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java index 270675f..8656a5a 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java @@ -11,6 +11,7 @@ import freshtrash.freshtrashbackend.domain.member.entity.constants.UserRole; import freshtrash.freshtrashbackend.global.exception.AuctionException; import freshtrash.freshtrashbackend.global.exception.constants.ErrorCode; +import freshtrash.freshtrashbackend.global.infra.RecSysService; import freshtrash.freshtrashbackend.global.infra.file.FileService; import freshtrash.freshtrashbackend.global.utils.FileUtils; import lombok.RequiredArgsConstructor; @@ -37,6 +38,7 @@ public class AuctionService { private final AuctionRepository auctionRepository; private final FileService fileService; private final BiddingHistoryService biddingHistoryService; + private final RecSysService recSysService; public AuctionResponse addAuction( MultipartFile imgFile, AuctionRequest auctionRequest, MemberPrincipal memberPrincipal) { @@ -46,6 +48,9 @@ public AuctionResponse addAuction( Auction savedAuction = auctionRepository.save(auction); // 이미지 파일 저장 fileService.uploadFile(imgFile, savedFileName); + // 경매 프로필 업데이트 + recSysService.createAuction(savedAuction); + return AuctionResponse.fromEntity(savedAuction, memberPrincipal); } diff --git a/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java b/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java index afd07fa..69c42cf 100644 --- a/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java +++ b/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java @@ -11,7 +11,9 @@ @ConfigurationProperties(prefix = "rec-sys") public record RecSysProperties( @NotBlank String host, - @NotBlank String productEndpoint, + @NotBlank String profileEndpoint, @NotBlank String productPurchase, + @NotBlank String auctionPurchase, @NotBlank String recommendProduct, + @NotBlank String recommendAuction, @Positive @NotNull Integer productLimit) {} diff --git a/src/main/java/freshtrash/freshtrashbackend/global/infra/RecSysService.java b/src/main/java/freshtrash/freshtrashbackend/global/infra/RecSysService.java index 2fc3dbb..ac4598d 100644 --- a/src/main/java/freshtrash/freshtrashbackend/global/infra/RecSysService.java +++ b/src/main/java/freshtrash/freshtrashbackend/global/infra/RecSysService.java @@ -1,5 +1,6 @@ package freshtrash.freshtrashbackend.global.infra; +import freshtrash.freshtrashbackend.domain.auction.entity.Auction; import freshtrash.freshtrashbackend.domain.product.entity.Product; import freshtrash.freshtrashbackend.global.config.properties.RecSysProperties; import freshtrash.freshtrashbackend.global.utils.RestUtils; @@ -25,7 +26,19 @@ public void createOrUpdateProduct(Product product) { messageBody.put("category", product.getProductCategory().getProfileIndex()); messageBody.put("title", product.getTitle()); messageBody.put("content", product.getContent()); - restUtils.put(new HttpEntity<>(messageBody), getUrl(recSysProperties.productEndpoint()), Void.class); + restUtils.put(new HttpEntity<>(messageBody), getUrl(recSysProperties.profileEndpoint()), Void.class); + } + + /** + * 경매 추가/수정 시 해당 상품의 프로필 정보 수정 + */ + public void createAuction(Auction auction) { + Map messageBody = new HashMap<>(); + messageBody.put("file_name", auction.getProfileFileName()); + messageBody.put("category", auction.getProductCategory().getProfileIndex()); + messageBody.put("title", auction.getTitle()); + messageBody.put("content", auction.getContent()); + restUtils.put(new HttpEntity<>(messageBody), getUrl(recSysProperties.profileEndpoint()), Void.class); } /** @@ -38,6 +51,16 @@ public void purchaseProduct(Long productId, Long memberId) { new HttpEntity<>(null), getUrl(recSysProperties.productPurchase(), productId, memberId), Void.class); } + /** + * 낙찰된 경매 상품 구매 시 구매자의 프로필 정보 수정 + * 1. 구매 횟수 + 1 + * 2. 경매 프로필 누적 합 계산 + */ + public void purchaseAuction(Long auctionId, Long memberId) { + restUtils.put( + new HttpEntity<>(null), getUrl(recSysProperties.auctionPurchase(), auctionId, memberId), Void.class); + } + private String getUrl(String endpoint) { return String.format("%s%s", recSysProperties.host(), endpoint); } From 43c4329079089a3203f9f5f69c253042a795b1db Mon Sep 17 00:00:00 2001 From: JadeKim042386 Date: Wed, 14 Aug 2024 13:27:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/infra/RecSysServiceTest.java | 23 +++++++++++++++++++ .../service/AuctionServiceTest.java | 5 ++++ .../alarm/CompletePayAuctionAlarmTest.java | 5 ++++ 3 files changed, 33 insertions(+) diff --git a/src/test/java/freshtrash/freshtrashbackend/global/infra/RecSysServiceTest.java b/src/test/java/freshtrash/freshtrashbackend/global/infra/RecSysServiceTest.java index 1ffc4f5..907c9d6 100644 --- a/src/test/java/freshtrash/freshtrashbackend/global/infra/RecSysServiceTest.java +++ b/src/test/java/freshtrash/freshtrashbackend/global/infra/RecSysServiceTest.java @@ -1,6 +1,7 @@ package freshtrash.freshtrashbackend.global.infra; import freshtrash.freshtrashbackend.Fixture.Fixture; +import freshtrash.freshtrashbackend.domain.auction.entity.Auction; import freshtrash.freshtrashbackend.domain.product.entity.Product; import freshtrash.freshtrashbackend.global.config.properties.RecSysProperties; import freshtrash.freshtrashbackend.global.utils.RestUtils; @@ -40,6 +41,17 @@ void given_product_when_requestPutByRest_then_returnVoid() { // then } + @DisplayName("경매의 프로필 정보를 수정하는 API를 요청한다.") + @Test + void given_auction_when_requestPutByRest_then_returnVoid() { + // given + Auction auction = Fixture.createAuction(); + given(restUtils.put(any(HttpEntity.class), anyString(), eq(Void.class))).willReturn(ResponseEntity.ok(null)); + // when + recSysService.createAuction(auction); + // then + } + @DisplayName("상품 구매 시 회원의 구매 횟수와 프로필 정보를 업데이트하는 API를 요청한다.") @Test void given_productIdAndMemberId_when_requestPutByRest_then_returnVoid() { @@ -50,4 +62,15 @@ void given_productIdAndMemberId_when_requestPutByRest_then_returnVoid() { recSysService.purchaseProduct(productId, memberId); // then } + + @DisplayName("낙찰된 경매 상품 구매 시 회원의 구매 횟수와 프로필 정보를 업데이트하는 API를 요청한다.") + @Test + void given_auctionIdAndMemberId_when_requestPutByRest_then_returnVoid() { + // given + Long auctionId = 1L, memberId = 2L; + given(restUtils.put(any(HttpEntity.class), anyString(), eq(Void.class))).willReturn(ResponseEntity.ok(null)); + // when + recSysService.purchaseAuction(auctionId, memberId); + // then + } } \ No newline at end of file diff --git a/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java b/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java index fb26818..012c356 100644 --- a/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java +++ b/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java @@ -14,6 +14,7 @@ import freshtrash.freshtrashbackend.domain.auction.service.BiddingHistoryService; import freshtrash.freshtrashbackend.domain.member.dto.security.MemberPrincipal; import freshtrash.freshtrashbackend.domain.member.entity.constants.UserRole; +import freshtrash.freshtrashbackend.global.infra.RecSysService; import freshtrash.freshtrashbackend.global.infra.file.LocalFileService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -56,6 +57,9 @@ class AuctionServiceTest { @Mock private BiddingHistoryService biddingHistoryService; + @Mock + private RecSysService recSysService; + @DisplayName("경매 추가") @Test void given_imageAndAuctionRequestData_when_addAuction_then_returnSavedAuctionData() { @@ -67,6 +71,7 @@ void given_imageAndAuctionRequestData_when_addAuction_then_returnSavedAuctionDat Auction auction = Auction.fromRequest(auctionRequest, fileName, memberPrincipal.id()); given(auctionRepository.save(any(Auction.class))).willReturn(auction); willDoNothing().given(fileService).uploadFile(eq(image), anyString()); + willDoNothing().given(recSysService).createAuction(auction); // when AuctionResponse auctionResponse = auctionService.addAuction(image, auctionRequest, memberPrincipal); // then diff --git a/src/test/java/freshtrash/freshtrashbackend/service/alarm/CompletePayAuctionAlarmTest.java b/src/test/java/freshtrash/freshtrashbackend/service/alarm/CompletePayAuctionAlarmTest.java index 406d9a8..6792562 100644 --- a/src/test/java/freshtrash/freshtrashbackend/service/alarm/CompletePayAuctionAlarmTest.java +++ b/src/test/java/freshtrash/freshtrashbackend/service/alarm/CompletePayAuctionAlarmTest.java @@ -5,6 +5,7 @@ import freshtrash.freshtrashbackend.domain.alarm.service.CompletePayAuctionAlarm; import freshtrash.freshtrashbackend.domain.alarm.service.parameter.BiddingHistoryAlarmParameter; import freshtrash.freshtrashbackend.domain.auction.entity.BiddingHistory; +import freshtrash.freshtrashbackend.global.infra.RecSysService; import freshtrash.freshtrashbackend.producer.AuctionProducer; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -27,6 +28,9 @@ class CompletePayAuctionAlarmTest { @Mock private AuctionProducer producer; + @Mock + private RecSysService recSysService; + @Test @DisplayName("낙찰된 경매 상품을 결제 완료하면 해당 입찰 내역의 결제 여부를 true로 변경하고 알림을 전송한다.") void given_biddingHistory_when_completePay_then_updatePayAndSendAlarm() { @@ -35,6 +39,7 @@ void given_biddingHistory_when_completePay_then_updatePayAndSendAlarm() { int price = 1000; BiddingHistory biddingHistory = Fixture.createBiddingHistory(auctionId, memberId, price); BiddingHistoryAlarmParameter biddingHistoryAlarmParameter = new BiddingHistoryAlarmParameter(biddingHistory); + willDoNothing().given(recSysService).purchaseAuction(auctionId, memberId); willDoNothing().given(producer).publishForCompletedPayAndRequestDelivery(biddingHistory); // when assertThatCode(() -> completePayAuctionAlarm.sendAlarm(biddingHistoryAlarmParameter)) From 9fec5c69a56ec76eef8ffa34465adc53cf753092 Mon Sep 17 00:00:00 2001 From: JadeKim042386 Date: Wed, 14 Aug 2024 13:27:59 +0900 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=EC=B6=94=EC=B2=9C=20=EC=8B=9C?= =?UTF-8?q?=EC=8A=A4=ED=85=9C=EA=B4=80=EB=A0=A8=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=86=8D=EC=84=B1=20=EA=B0=92=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose-local.yml | 6 ++++-- .../global/config/properties/RecSysProperties.java | 2 +- src/main/resources/application-common.yml | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docker-compose-local.yml b/docker-compose-local.yml index 18f41cf..7e49250 100644 --- a/docker-compose-local.yml +++ b/docker-compose-local.yml @@ -78,10 +78,12 @@ services: - API_KEY=${API_KEY} - WEBHOOK_SLACK_URL=${WEBHOOK_SLACK_URL} - REC_SYS_HOST=${REC_SYS_HOST} - - REC_PRODUCT_ENDPOINT=${REC_PRODUCT_ENDPOINT} + - PROFILE_ENDPOINT=${PROFILE_ENDPOINT} - REC_PRODUCT_PURCHASE=${REC_PRODUCT_PURCHASE} + - REC_AUCTION_PURCHASE=${REC_AUCTION_PURCHASE} - RECOMMEND_PRODUCT=${RECOMMEND_PRODUCT} - - REC_PRODUCT_LIMIT=${REC_PRODUCT_LIMIT} + - RECOMMEND_AUCTION=${RECOMMEND_AUCTION} + - REC_LIMIT=${REC_LIMIT} ports: - "8080:8080" - "8090:8090" diff --git a/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java b/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java index 69c42cf..c6d5fd4 100644 --- a/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java +++ b/src/main/java/freshtrash/freshtrashbackend/global/config/properties/RecSysProperties.java @@ -16,4 +16,4 @@ public record RecSysProperties( @NotBlank String auctionPurchase, @NotBlank String recommendProduct, @NotBlank String recommendAuction, - @Positive @NotNull Integer productLimit) {} + @Positive @NotNull Integer recommendLimit) {} diff --git a/src/main/resources/application-common.yml b/src/main/resources/application-common.yml index ac95015..9d019f3 100644 --- a/src/main/resources/application-common.yml +++ b/src/main/resources/application-common.yml @@ -30,7 +30,9 @@ webhook: rec-sys: host: ${REC_SYS_HOST} - product-endpoint: ${REC_PRODUCT_ENDPOINT} + profile-endpoint: ${PROFILE_ENDPOINT} product-purchase: ${REC_PRODUCT_PURCHASE} + auction-purchase: ${REC_AUCTION_PURCHASE} recommend-product: ${RECOMMEND_PRODUCT} - product-limit: ${REC_PRODUCT_LIMIT} + recommend-auction: ${RECOMMEND_AUCTION} + recommend-limit: ${REC_LIMIT}