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

Add server-side pagination capability to GraphQL APIs #21

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 8 additions & 3 deletions src/main/java/com/shareNwork/resource/AccessRequestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import java.util.List;

import javax.transaction.TransactionScoped;
import javax.transaction.Transactional;

import com.shareNwork.domain.AccessRequest;
import com.shareNwork.domain.Invitation;
import com.shareNwork.domain.InvitationResponse;
import com.shareNwork.domain.constants.InvitationStatus;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

@AllArgsConstructor
Expand All @@ -25,6 +24,12 @@ public List<AccessRequest> findAllRequests() {
return AccessRequest.listAll();
}

@Query("accessRequestsByPage")
@Description("Get AccessRequests with pagination")
public List<AccessRequest> getAccessRequestsByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return AccessRequest.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Mutation
@Description("Create a new access request")
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.shareNwork.resource;

import com.shareNwork.domain.AllowedDesignationResponse;
import com.shareNwork.domain.InvitationResponse;
import com.shareNwork.repository.AllowedDesignationRepository;
import com.shareNwork.repository.EmployeeRepository;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
Expand All @@ -15,7 +13,7 @@ public class AllowedDesignationResource {
private AllowedDesignationRepository allowedDesignationRepository;

@Mutation
@Description("Check whether desg8ination is whitelisted")
@Description("Check whether designation is whitelisted")
public AllowedDesignationResponse verifyDesignation(String designation) {
return this.allowedDesignationRepository.verify(designation);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/shareNwork/resource/EmployeeResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.shareNwork.domain.Employee;
import com.shareNwork.domain.filters.EmployeeFilter;
import com.shareNwork.repository.EmployeeRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.*;

Expand All @@ -21,6 +22,12 @@ public List<Employee> findAll() {
return this.employeeRepository.findAll().list();
}

@Query("employeesByPage")
@Description("Get employees with pagination")
public List<Employee> getEmployeesByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.employeeRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Query("employeesWithFilter")
@Description("Get all Employees using the filters eq, lt,le,gt,ge")
public List<Employee> findWithFilter(@Name("filter") EmployeeFilter filter) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/shareNwork/resource/InvitationResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.shareNwork.domain.Invitation;
import com.shareNwork.domain.InvitationResponse;
import com.shareNwork.repository.InvitationRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

import java.util.List;
Expand All @@ -29,6 +31,12 @@ public Invitation getInvitationById(long id) {
return this.invitationRepository.findById(id);
}

@Query("invitationsByPage")
@Description("Get Invitations with pagination")
public List<Invitation> getInvitationsByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.invitationRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Mutation
@Description("Create a new token")
public InvitationResponse createInvitationToken(Invitation invitation) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/shareNwork/resource/ProjectResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.shareNwork.domain.Project;
import com.shareNwork.repository.ProjectRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

import java.text.ParseException;
Expand All @@ -23,6 +25,12 @@ public List<Project> findAll() {
return this.projectRepository.findAll().list();
}

@Query("projectsByPage")
@Description("Get projects with pagination")
public List<Project> getProjectsByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.projectRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Mutation
@Description("Create a new Employee")
public Project createProject(Project project) throws ParseException {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/shareNwork/resource/SRRequestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import com.shareNwork.domain.ResourceRequest;
import com.shareNwork.domain.ResourceRequestSkillsProficiency;
import com.shareNwork.domain.SharedResource;
import com.shareNwork.repository.ResourceRequestRepository;
import com.shareNwork.repository.SharedResourceRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

import javax.transaction.Transactional;
import java.text.ParseException;
import java.util.List;
import java.util.Set;

@AllArgsConstructor
@GraphQLApi
Expand All @@ -29,6 +28,12 @@ public List<ResourceRequest> getAllSharedResourceRequest() {
return resourceRequestRepository.listAll();
}

@Query("sharedResourceRequestsByPage")
@Description("Get SharedResourceRequest with pagination")
public List<ResourceRequest> getAccessRequestsByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.resourceRequestRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Query("getSkillsByRequestId")
@Description("Get required skills of request Id")
@Transactional
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/shareNwork/resource/SharedResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.shareNwork.domain.EmployeeSkillProficiency;
import com.shareNwork.domain.filters.EmployeeFilter;
import com.shareNwork.repository.SharedResourceRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.*;

Expand All @@ -24,6 +25,11 @@ public List<com.shareNwork.domain.SharedResource> getAllSharedResource() {
return this.sharedResourceRepository.listAll();
}

@Query("sharedResourcesByPage")
@Description("Get SharedResource with pagination")
public List<com.shareNwork.domain.SharedResource> getSharedResourcesByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.sharedResourceRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}
@Query("sharedResourceById")
@Description("Get an SR by id")
public com.shareNwork.domain.SharedResource getSRById(@Name("id") Long id) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/shareNwork/resource/SkillResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.shareNwork.domain.Skill;
import com.shareNwork.repository.SkillRepository;
import io.quarkus.panache.common.Page;
import lombok.AllArgsConstructor;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

import java.text.ParseException;
Expand All @@ -22,6 +24,12 @@ public List<Skill> findAll() {
return this.skillRepository.findAll().list();
}

@Query("skillsByPage")
@Description("Get Kills with pagination")
public List<Skill> getSkillsByPage(@Name("pageSize") int pageSize, @Name("pageOffset") int pageOffset) {
return this.skillRepository.findAll().page(Page.of(pageOffset, pageSize)).list();
}

@Mutation
@Description("Add a new skill")
public Skill createSkill(Skill skill) throws ParseException {
Expand Down