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}/credentials API #4095

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 @@ -12,11 +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.authentication.credential.Credential;
Expand All @@ -27,20 +43,6 @@
import org.eclipse.kapua.service.authentication.credential.CredentialQuery;
import org.eclipse.kapua.service.authentication.credential.CredentialService;

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}/credentials")
public class Credentials extends AbstractKapuaResource {

Expand All @@ -66,6 +68,8 @@
public CredentialListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("userId") EntityId userId,
@QueryParam("sortParam") String sortParam,
@QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
CredentialQuery query = credentialFactory.newQuery(scopeId);
Expand All @@ -74,6 +78,9 @@
if (userId != null) {
andPredicate.and(query.attributePredicate(CredentialAttributes.USER_ID, userId));
}
if (!Strings.isNullOrEmpty(sortParam)) {
query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir));

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

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Credentials.java#L82

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

query.setOffset(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ paths:
description: The optional id to filter results
schema:
$ref: '../openapi.yaml#/components/schemas/kapuaId'
- $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'

Expand Down
Loading