Files
microservice-b/src/main/java/com/example/mmad/testapp/command/OrderCommandHandler.java
esmailian c462b79e98 add order command query for test in project and add consumer kfka for test event driven read model design pattern
dont forget change implementation of kafka consumer to list of values
2025-04-28 15:54:16 +03:30

34 lines
1.3 KiB
Java

package com.example.mmad.testapp.command;
import com.example.mmad.testapp.entity.OrderEntity;
import com.example.mmad.testapp.event.OrderCreatedEvent;
import com.example.mmad.testapp.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
@Service
public class OrderCommandHandler {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
private final UserRepository userRepository;
public OrderCommandHandler(UserRepository userRepository) {
this.userRepository = userRepository;
}
public void createUser(CreateOrderCommand createUserCommand) {
OrderEntity orderEntity = new OrderEntity();
orderEntity.setId(createUserCommand.getOrderId());
orderEntity.setOrderName(createUserCommand.getOrderName());
orderEntity.setDescription(createUserCommand.getDescription());
// userRepository.save(orderEntity);
OrderCreatedEvent event = new OrderCreatedEvent(
orderEntity.getId(),
orderEntity.getOrderName(),
orderEntity.getDescription()
);
applicationEventPublisher.publishEvent(event);
}
}