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

✨ [REST API] Implement sorting functionality in /{scopeId}/roles API #4093

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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 @@ -84,9 +84,6 @@ 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import java.util.List;
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;
Expand All @@ -36,21 +51,6 @@
import org.eclipse.kapua.service.user.UserQuery;
import org.eclipse.kapua.service.user.UserService;

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 java.util.List;

@Path("{scopeId}/roles")
public class Roles extends AbstractKapuaResource {

Expand Down Expand Up @@ -81,6 +81,8 @@
@QueryParam("name") String name,
@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 {
RoleQuery query = roleFactory.newQuery(scopeId);
Expand All @@ -92,6 +94,9 @@
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));
}
if (!Strings.isNullOrEmpty(sortParam)) {
query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir));

Check warning on line 98 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java#L98

Added line #L98 was not covered by tests
}
query.setPredicate(andPredicate);

query.setAskTotalCount(askTotalCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ paths:
schema:
type: string
- $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
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
responses:
Expand Down
Loading