Search in sources :

Example 1 with Customer

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;
}
Also used : SearchCustomerResponse(app.demo.api.customer.SearchCustomerResponse) Customer(app.demo.customer.domain.Customer)

Example 2 with Customer

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);
}
Also used : Customer(app.demo.customer.domain.Customer) ConflictException(core.framework.web.exception.ConflictException)

Example 3 with 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);
}
Also used : Customer(app.demo.customer.domain.Customer) NotFoundException(core.framework.web.exception.NotFoundException)

Aggregations

Customer (app.demo.customer.domain.Customer)3 SearchCustomerResponse (app.demo.api.customer.SearchCustomerResponse)1 ConflictException (core.framework.web.exception.ConflictException)1 NotFoundException (core.framework.web.exception.NotFoundException)1