Skip to content

Commit

Permalink
✨ LF1-838 주문 발생 시 상품 판매량 증가
Browse files Browse the repository at this point in the history
  • Loading branch information
nowgnas committed Dec 24, 2023
1 parent 15f7533 commit fed8c88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kr.bb.product.domain.product.entity.Product;
import kr.bb.product.domain.product.mapper.ProductCommand.UpdateSubscriptionProduct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.BulkOperations;
import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -15,6 +16,7 @@
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
@RequiredArgsConstructor
public class ProductCommandRepository implements ProductCommandOutPort {
Expand Down Expand Up @@ -54,10 +56,10 @@ public void updateProductReviewData(ReviewRegisterEvent reviewRegisterEvent) {

@Override
public void updateProductSaleCount(List<ProductCount> newOrderEvent) {
BulkOperations bulkOperations = mongoTemplate.bulkOps(BulkMode.UNORDERED, "product");
BulkOperations bulkOperations = mongoTemplate.bulkOps(BulkMode.UNORDERED, Product.class);
for (ProductCount products : newOrderEvent) {
Query query = Query.query(Criteria.where("_id").is(products.getProductId()));
Update update = new Update().inc("product_sale_amount", products.getQuantity());
Update update = new Update().inc("productSaleAmount", products.getQuantity());
bulkOperations.updateOne(query, update);
}
bulkOperations.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class ProductSQSListener {
private final ObjectMapper objectMapper;
private final ProductCommandHandler productHandler;

/**
* 상품 리뷰 작성 시 상품 리뷰 정보 업데이트
*
* @param message
* @param headers
* @param ack
* @throws JsonProcessingException
*/
@SqsListener(
value = "${cloud.aws.sqs.product-review-data-update-queue.name}",
deletionPolicy = SqsMessageDeletionPolicy.NEVER)
Expand All @@ -38,6 +46,14 @@ public void consumeProductReviewDataUpdateQueue(
ack.acknowledge();
}

/**
* 상품 주문 시 판매량 증가
*
* @param message
* @param headers
* @param ack
* @throws JsonProcessingException
*/
@SqsListener(
value = "${cloud.aws.sqs.sale-count-update-queue.name}",
deletionPolicy = SqsMessageDeletionPolicy.NEVER)
Expand All @@ -46,8 +62,7 @@ public void consumeSaleCountUpdateQueue(
throws JsonProcessingException {
String messageFromSNS = getMessageFromSNS(message);

NewOrderEvent newOrderEvent =
objectMapper.readValue(messageFromSNS, NewOrderEvent.class);
NewOrderEvent newOrderEvent = objectMapper.readValue(messageFromSNS, NewOrderEvent.class);

productHandler.saleCountUpdate(newOrderEvent);
ack.acknowledge();
Expand Down

0 comments on commit fed8c88

Please sign in to comment.