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
This commit is contained in:
esmailian
2025-04-28 15:54:16 +03:30
parent 8a986212c4
commit c462b79e98
13 changed files with 129 additions and 92 deletions

View File

@ -0,0 +1,33 @@
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);
}
}