34 lines
1.3 KiB
Java
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);
|
|
}
|
|
}
|