use of core.framework.web.exception.ConflictException in project core-ng-demo-project by neowu.
the class CustomerService method create.
public CustomerView create(CreateCustomerRequest request) {
Optional<Customer> existingCustomer = customerRepository.selectOne("email = ?", request.email);
if (existingCustomer.isPresent()) {
throw new ConflictException("customer already exists, email=" + request.email);
}
Customer customer = new Customer();
customer.email = request.email;
customer.firstName = request.firstName;
customer.lastName = request.lastName;
customer.updatedTime = LocalDateTime.now();
customer.id = customerRepository.insert(customer).get();
return view(customer);
}
Aggregations