Skip to content
Snippets Groups Projects
Commit 2bac3e5e authored by Tobias Gross-Vogt's avatar Tobias Gross-Vogt
Browse files

pagination update

parent dc149733
No related branches found
No related tags found
No related merge requests found
Pipeline #184473 passed
......@@ -172,14 +172,8 @@
"version": "dev-main",
"source": {
"type": "git",
"url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle.git",
"reference": "766488dd1db1778632dedd0752f89e065c68a2da"
},
"dist": {
"type": "zip",
"url": "https://gitlab.tugraz.at/api/v4/projects/dbp%2Frelay%2Fdbp-relay-core-bundle/repository/archive.zip?sha=766488dd1db1778632dedd0752f89e065c68a2da",
"reference": "766488dd1db1778632dedd0752f89e065c68a2da",
"shasum": ""
"url": "git@gitlab.tugraz.at:dbp/relay/dbp-relay-core-bundle.git",
"reference": "c7bab5379711297e01e7d53c231d295d732e1d45"
},
"require": {
"api-platform/core": "^2.6.6",
......@@ -275,11 +269,7 @@
"AGPL-3.0-or-later"
],
"description": "The core bundle of the Relay API gateway",
"support": {
"source": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle/-/tree/main",
"issues": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle/-/issues"
},
"time": "2022-06-11T02:25:45+02:00"
"time": "2022-06-21T09:42:10+00:00"
},
{
"name": "doctrine/annotations",
......@@ -10064,5 +10054,5 @@
"platform-overrides": {
"php": "7.3"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.2.0"
}
......@@ -5,34 +5,32 @@ declare(strict_types=1);
namespace Dbp\Relay\BaseCourseBundle\Controller;
use Dbp\Relay\BaseCourseBundle\API\CourseProviderInterface;
use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
use Dbp\Relay\CoreBundle\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Pagination\Paginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class GetAttendeesByCourse extends AbstractController
{
public const ITEMS_PER_PAGE = 250;
public const MAX_ITEMS_PER_PAGE = 250;
protected $coursesProvider;
/** @var CourseProviderInterface */
private $coursesProvider;
public function __construct(CourseProviderInterface $coursesProvider)
{
$this->coursesProvider = $coursesProvider;
}
public function __invoke(string $identifier, Request $request): ArrayFullPaginator
public function __invoke(string $identifier, Request $request): Paginator
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$page = (int) $request->query->get('page', 1);
$perPage = (int) $request->query->get('perPage', self::ITEMS_PER_PAGE);
$options = [];
$lang = $request->query->get('lang', 'de');
$options['lang'] = $lang;
$options['lang'] = $request->query->get('lang', 'de');
$courses = $this->coursesProvider->getAttendeesByCourse($identifier, $options);
Pagination::addPaginationOptions($options, $request->query->all(), self::MAX_ITEMS_PER_PAGE);
return new ArrayFullPaginator($courses, $page, $perPage);
return $this->coursesProvider->getAttendeesByCourse($identifier, $options);
}
}
......@@ -17,13 +17,9 @@ final class CourseCollectionDataProvider extends AbstractController implements C
/** @var CourseProviderInterface */
private $courseProvider;
/** @var Pagination */
private $pagination;
public function __construct(CourseProviderInterface $courseProvider, Pagination $pagination)
public function __construct(CourseProviderInterface $courseProvider)
{
$this->courseProvider = $courseProvider;
$this->pagination = $pagination;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
......@@ -36,7 +32,6 @@ final class CourseCollectionDataProvider extends AbstractController implements C
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$filters = $context['filters'] ?? [];
$options = [];
$options['lang'] = $filters['lang'] ?? 'de';
......@@ -58,9 +53,11 @@ final class CourseCollectionDataProvider extends AbstractController implements C
$filterByOrganizationId = $organizationId !== '';
$filterByLecturerId = $lecturerId !== '';
dump($context);
if (!($filterByOrganizationId && $filterByLecturerId)) {
$this->pagination->addPaginationOptions($options, $resourceClass, $operationName, $context);
} // else -> request the whole set of results
Pagination::addPaginationOptions($options, $filters);
} // else (both filters provided) -> request paginators holding the whole set of results since we need to intersect them
$coursePaginator = null;
if ($filterByOrganizationId || $filterByLecturerId) {
......@@ -76,7 +73,8 @@ final class CourseCollectionDataProvider extends AbstractController implements C
$intersection = array_uintersect($coursePaginator->getItems(), $coursesByPersonPaginator->getItems(),
'Dbp\Relay\BaseCourseBundle\DataProvider\CourseCollectionDataProvider::compareCourses');
$courses = array_values($intersection);
$coursePaginator = $this->pagination->createWholeResultPaginator($courses, $resourceClass, $operationName, $context);
Pagination::addPaginationOptions($options, $filters);
$coursePaginator = Pagination::createWholeResultPaginator($courses, $options);
}
}
} else {
......
......@@ -13,6 +13,8 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait;
* collectionOperations={
* "get" = {
* "path" = "/base/courses",
* "security" = "is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_client_partial" = true,
* "openapi_context" = {
* "tags" = {"BaseCourse"},
* "parameters" = {
......@@ -21,7 +23,8 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait;
* {"name" = "term", "in" = "query", "description" = "Teaching term", "type" = "string", "enum" = {"W", "S"}, "example" = "W"},
* {"name" = "organization", "in" = "query", "description" = "Get courses of an organization (ID of BaseOrganization resource)", "required" = false, "type" = "string", "example" = "1190"},
* {"name" = "lecturer", "in" = "query", "description" = "Get courses of a lecturer (ID of BasePerson resource)", "required" = false, "type" = "string", "example" = "woody007"},
* {"name" = "includeLocal", "in" = "query", "description" = "Local data attributes to include", "type" = "string", "example" = "BaseCourse.code,BaseCourse.numberOfCredits"}
* {"name" = "includeLocal", "in" = "query", "description" = "Local data attributes to include", "type" = "string", "example" = "BaseCourse.code,BaseCourse.numberOfCredits"},
* {"name" = "partialPagination", "in" = "query", "description" = "Enable partial pagination", "type" = "bool", "example" = "false"}
* }
* }
* }
......@@ -29,6 +32,7 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait;
* itemOperations={
* "get" = {
* "path" = "/base/courses/{identifier}",
* "security" = "is_granted('IS_AUTHENTICATED_FULLY')",
* "openapi_context" = {
* "tags" = {"BaseCourse"},
* "parameters" = {
......@@ -48,4 +52,6 @@ class Course implements CourseInterface, LocalDataAwareInterface
{
use LocalDataAwareTrait;
use CourseTrait;
public const SEARCH_PARAMETER_NAME = 'search';
}
......@@ -23,6 +23,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
* "method" = "GET",
* "path" = "/base/courses/{identifier}/attendees",
* "security" = "is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_client_partial" = true,
* "controller" = GetAttendeesByCourse::class,
* "read" = false,
* "normalization_context" = {
......@@ -34,7 +35,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
* "summary" = "Get the attendees of a course.",
* "parameters" = {
* {"name" = "identifier", "in" = "path", "description" = "Resource identifier", "required" = true, "type" = "string", "example" = "257571"},
* {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}
* {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"},
* {"name" = "partial", "in" = "query", "description" = "Enable partial pagination", "type" = "bool", "example" = "false"}
* }
* }
* }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment