Skip to content

Commit

Permalink
Merge pull request #160 from HS-Continuity/KAN-701--feat/카프카이벤트발행수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimujae authored Aug 6, 2024
2 parents f952f05 + 2cce950 commit 2d2b4e2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ProductAdvertisementService toEntity(Product product, ServiceStatus statu
.build();
}

public AdvertisementEventMessage toEventMessage() {
public AdvertisementEventMessage toEventMessage(Long id) {
return AdvertisementEventMessage.builder()
.productId(this.getProductId())
.productId(id)
.startDate(this.getStartDate())
.endDate(this.getEndDate())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public ProductTimesale toEntity(Product product, ServiceStatus serviceStatus) {
.build();
}

public TimesaleEventMessage toEventMessage() {
public TimesaleEventMessage toEventMessage(Long id) {
return TimesaleEventMessage.builder()
.startDateTime(this.getStartTime())
.endDateTime(this.getEndTime())
.productId(this.getProductId())
.productId(id)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class AdvertisementManagementService {
private final ProductRepository productRepository;
private final ProductAdvertisementServiceRepository productAdvertisementServiceRepository;
private final ServiceStatusRepository serviceStatusRepository;
private final ProductEventProducer productEventProducer;

/**
* 상당노출신청상품리스트 조회
Expand All @@ -59,18 +58,17 @@ public List<AdvertisementResponse.OfRetrieve> retrieveAppliedProduct(Long custom
* @return
*/
@Transactional
public void registerAdvertisement(Long customerId, AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException {
public Long registerAdvertisement(Long customerId, AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException {
Product product = productRepository.findByProductIdAndCustomer_CustomerId(registerRequest.getProductId(), customerId);
if(product == null) {
throw new ProductException(PRODUCT_NOT_FOUND, HttpStatus.NOT_FOUND);
}

ServiceStatus status = serviceStatusRepository.findByStatusName(ServiceStatusCode.PENDING.getCode());
ProductAdvertisementService productAdvertisement = registerRequest.toEntity(product, status);
productAdvertisementServiceRepository.save(productAdvertisement);
ProductAdvertisementService savedEntity = productAdvertisementServiceRepository.save(productAdvertisement);

AdvertisementEventMessage advertisementEventMessage = registerRequest.toEventMessage();
productEventProducer.sendMessage(advertisementEventMessage);
return savedEntity.getProductAdvertisementServiceId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class TimesaleManagementService {
private final ProductRepository productRepository;
private final ProductTimesaleRepository productTimesaleRepository;
private final ServiceStatusRepository serviceStatusRepository;
private final ProductEventProducer productEventProducer;

/**
* 고객의 등록타임세일 목록 조회
Expand Down Expand Up @@ -83,18 +82,17 @@ public TimesaleResponseForCustomer.OfRetrieve retrieveCustomersTimesale(Long cus
* @return
*/
@Transactional
public void registerTimesale(Long customerId, TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException {
public Long registerTimesale(Long customerId, TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException {
Product product = productRepository.findByProductIdAndCustomer_CustomerId(registerRequest.getProductId(), customerId);
if(product == null) {
throw new ProductException(PRODUCT_NOT_FOUND, HttpStatus.NOT_FOUND);
}

ServiceStatus status = serviceStatusRepository.findByStatusName(ServiceStatusCode.PENDING.getCode());
ProductTimesale productTimesale = registerRequest.toEntity(product, status);
productTimesaleRepository.save(productTimesale);
ProductTimesale savedEntity = productTimesaleRepository.save(productTimesale);

TimesaleEventMessage timesaleEventMessage = registerRequest.toEventMessage();
productEventProducer.sendMessage(timesaleEventMessage);
return savedEntity.getProductTimesaleId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.yeonieum.productservice.global.responses.ApiResponse;
import com.yeonieum.productservice.global.responses.code.SuccessCode;
import com.yeonieum.productservice.global.usercontext.UserContextHolder;
import com.yeonieum.productservice.infrastructure.messaging.ProductEventProducer;
import com.yeonieum.productservice.infrastructure.messaging.message.AdvertisementEventMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
Expand All @@ -26,6 +28,8 @@ public class AdvertisementController {

private final AdvertisementManagementService advertisementManagementService;
private final AdvertisementService advertisementService;
private final ProductEventProducer productEventProducer;


/**
* 상품광고서비스 신청
Expand Down Expand Up @@ -61,8 +65,10 @@ public ResponseEntity getAdvertisement(@RequestParam int startPage,
@PostMapping("/product")
public ResponseEntity registerAdvertisement(@Valid @RequestBody AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException {
Long customer = Long.valueOf(UserContextHolder.getContext().getUniqueId());
advertisementManagementService.registerAdvertisement(customer, registerRequest);
Long id= advertisementManagementService.registerAdvertisement(customer, registerRequest);

AdvertisementEventMessage advertisementEventMessage = registerRequest.toEventMessage(id);
productEventProducer.sendMessage(advertisementEventMessage);
return new ResponseEntity(ApiResponse.builder()
.result(null)
.successCode(SuccessCode.INSERT_SUCCESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.yeonieum.productservice.global.responses.ApiResponse;
import com.yeonieum.productservice.global.responses.code.SuccessCode;
import com.yeonieum.productservice.global.usercontext.UserContextHolder;
import com.yeonieum.productservice.infrastructure.messaging.ProductEventProducer;
import com.yeonieum.productservice.infrastructure.messaging.message.TimesaleEventMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
Expand All @@ -29,6 +31,8 @@
public class TimesaleController {
private final TimesaleManagementService timesaleManagementService;
private final TimesaleManagementFacade timesaleManagementFacade;
private final ProductEventProducer productEventProducer;


// TimesaleService의 메서드를 바탕으로 타임세일 조회, 등록, 타임세일 상품 조회를 구현해주세요.
// 타임세일 조회, 등록, 타임세일 상품 조회를 위한 API를 구현해주세요.
Expand Down Expand Up @@ -59,8 +63,9 @@ public ResponseEntity<ApiResponse> getTimesale() {
@PostMapping
public ResponseEntity<ApiResponse> registerTimesale(@Valid @RequestBody TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException {
Long customer = Long.valueOf(UserContextHolder.getContext().getUserId());
timesaleManagementService.registerTimesale(customer, registerRequest);

Long id = timesaleManagementService.registerTimesale(customer, registerRequest);
TimesaleEventMessage timesaleEventMessage = registerRequest.toEventMessage(id);
productEventProducer.sendMessage(timesaleEventMessage);
return new ResponseEntity<>(ApiResponse.builder()
.result(null)
.successCode(SuccessCode.INSERT_SUCCESS)
Expand Down

0 comments on commit 2d2b4e2

Please sign in to comment.