Search in sources :

Example 1 with SearchCustomerResponse

use of app.demo.api.customer.SearchCustomerResponse 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)

Aggregations

SearchCustomerResponse (app.demo.api.customer.SearchCustomerResponse)1 Customer (app.demo.customer.domain.Customer)1