Skip to content

Commit

Permalink
feat: 경매 추천 시스템 반영
Browse files Browse the repository at this point in the history
- 경매는 추가만 할 수 있기 때문에 추가할 때 경매 프로필을 수정 요청
- 낙찰된 경매를 결제(구매)할 때 구매한 회원의 프로필을 수정 요청
  • Loading branch information
JadeKim042386 committed Aug 14, 2024
1 parent 6655200 commit 05a82da
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
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;

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -46,6 +48,9 @@ public AuctionResponse addAuction(
Auction savedAuction = auctionRepository.save(auction);
// 이미지 파일 저장
fileService.uploadFile(imgFile, savedFileName);
// 경매 프로필 업데이트
recSysService.createAuction(savedAuction);

return AuctionResponse.fromEntity(savedAuction, memberPrincipal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Object> 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);
}

/**
Expand All @@ -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);
}
Expand Down

0 comments on commit 05a82da

Please sign in to comment.