use of app.demo.customer.domain.Customer in project core-ng-demo-project by neowu.
the class CustomerService method search.
public SearchCustomerResponse search(SearchCustomerRequest request) {
SearchCustomerResponse result = new SearchCustomerResponse();
Query<Customer> query = customerRepository.select();
query.skip(request.skip).limit(request.limit);
if (!Strings.isEmpty(request.email)) {
query.where("email = ?", request.email);
}
if (!Strings.isEmpty(request.firstName)) {
query.where("first_name like ?", Strings.format("{}%", request.firstName));
}
if (!Strings.isEmpty(request.lastName)) {
query.where("last_name like ?", Strings.format("{}%", request.lastName));
}
result.customers = query.fetch().stream().map(this::view).collect(Collectors.toList());
result.total = query.count();
return result;
}
use of app.demo.customer.domain.Customer 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);
}
use of app.demo.customer.domain.Customer in project core-ng-demo-project by neowu.
the class CustomerService method update.
public CustomerView update(Long id, UpdateCustomerRequest request) {
Customer customer = customerRepository.get(id).orElseThrow(() -> new NotFoundException("customer not found, id=" + id));
customer.updatedTime = LocalDateTime.now();
customer.firstName = request.firstName;
if (request.lastName != null) {
customer.lastName = request.lastName;
}
customerRepository.update(customer);
return view(customer);
}
Aggregations