Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Queried API call example #26

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package com.kumuluz.ee.samples.rest;

import com.kumuluz.ee.rest.beans.Queried;
import com.kumuluz.ee.rest.beans.QueryParameters;

import javax.enterprise.context.RequestScoped;
Expand All @@ -30,6 +31,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Benjamin Kastelic, Marko Skrjanec
Expand All @@ -49,8 +51,13 @@ public class CustomerResource {

@GET
public Response getAllCustomers() {
List<Customer> customers = customerBean.getCustomers(createQuery());
return Response.ok(customers).build();
Queried<Customer> customers = customerBean.getCustomers(createQuery());

List<Customer> response = customers.stream()
//.map() // my api object mapper
.collect(Collectors.toList());

return Response.ok(response).header("total", customers.getTotalCount()).build();
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* out of or in connection with the software or the use or other dealings in the
* software. See the License for the specific language governing permissions and
* limitations under the License.
*/
*/
package com.kumuluz.ee.samples.rest;

import com.kumuluz.ee.rest.beans.Queried;
import com.kumuluz.ee.rest.beans.QueryParameters;
import com.kumuluz.ee.rest.utils.JPAUtils;

import javax.enterprise.context.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import java.util.List;

/**
* @author Benjamin Kastelic, Marko Skrjanec
Expand All @@ -43,9 +43,9 @@ public Customer getCustomer(String customerId) {
return em.find(Customer.class, customerId);
}

public List<Customer> getCustomers(QueryParameters query) {
List<Customer> customers = JPAUtils.queryEntities(em, Customer.class, query);
return customers;
public Queried<Customer> getCustomers(QueryParameters query) {
Queried<Customer> customersQueried = JPAUtils.getQueried(em, Customer.class, query);
return customersQueried;
}


Expand Down