Skip to content

Commit

Permalink
Merge pull request #4090 from MDeLuise/improve-sortEndpointInfo
Browse files Browse the repository at this point in the history
✨ [REST API] Implement sorting functionality in `/{scopeId}/endpointInfos` API
  • Loading branch information
Coduz authored Jul 31, 2024
2 parents a0f753e + bdbed8e commit ca5615b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.common.base.Strings;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.core.model.CountResult;
import org.eclipse.kapua.app.api.core.model.EntityId;
import org.eclipse.kapua.app.api.core.model.ScopeId;
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
import org.eclipse.kapua.model.query.SortOrder;
import org.eclipse.kapua.model.query.predicate.AndPredicate;
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.endpoint.EndpointInfo;
Expand All @@ -28,20 +43,6 @@
import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;
import org.eclipse.kapua.service.endpoint.EndpointInfoService;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("{scopeId}/endpointInfos")
public class EndpointInfos extends AbstractKapuaResource {

Expand Down Expand Up @@ -70,6 +71,8 @@ public EndpointInfoListResult simpleQuery(
@QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType,
@QueryParam("matchTerm") String matchTerm,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("sortParam") String sortParam,
@QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
EndpointInfoQuery query = endpointInfoFactory.newQuery(scopeId);
Expand All @@ -81,6 +84,12 @@ public EndpointInfoListResult simpleQuery(
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));
}
if (!Strings.isNullOrEmpty(sortParam)) {
query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir));
}
query.setPredicate(andPredicate);

query.setOffset(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ paths:
type: string
- $ref: './endpointInfo.yaml#/components/parameters/endpointType'
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- $ref: '../openapi.yaml#/components/parameters/sortParam'
- name: sortDir
in: query
description: The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive (except for "clientId" parameter).
schema:
type: string
enum:
- ASCENDING
- DESCENDING
default: ASCENDING
- name: matchTerm
in: query
description: |
Expand Down

0 comments on commit ca5615b

Please sign in to comment.