diff --git a/composer.lock b/composer.lock index af40650abb8c7a09feea0bf3b51f4d26389ca83e..989ddeb5e91a548971e580cde491ed3036ba6398 100644 --- a/composer.lock +++ b/composer.lock @@ -173,7 +173,7 @@ "source": { "type": "git", "url": "git@gitlab.tugraz.at:dbp/relay/dbp-relay-core-bundle.git", - "reference": "4ede1874cf2f75680fdf0aa839ee358f4c3a4b5d" + "reference": "106d795fda10967c6202e3157b8bb1861bd9d2f7" }, "require": { "api-platform/core": "^2.6.6", @@ -269,7 +269,7 @@ "AGPL-3.0-or-later" ], "description": "The core bundle of the Relay API gateway", - "time": "2022-04-21T13:52:29+00:00" + "time": "2022-04-28T10:48:16+00:00" }, { "name": "doctrine/annotations", diff --git a/src/DataProvider/CourseCollectionDataProvider.php b/src/DataProvider/CourseCollectionDataProvider.php index 1c631d854fd24a7a44a0f95614fda80494dd9307..ae55b07e7709e01c39cd2969bfed2984d752a34c 100644 --- a/src/DataProvider/CourseCollectionDataProvider.php +++ b/src/DataProvider/CourseCollectionDataProvider.php @@ -9,6 +9,7 @@ use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use Dbp\Relay\BaseCourseBundle\API\CourseProviderInterface; use Dbp\Relay\BaseCourseBundle\Entity\Course; use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; +use Dbp\Relay\CoreBundle\LocalData\LocalData; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; final class CourseCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface @@ -38,9 +39,7 @@ final class CourseCollectionDataProvider extends AbstractController implements C $options['term'] = $term; } - if ($include = ($filters['include'] ?? null)) { - $options['include'] = $include; - } + $options[LocalData::INCLUDE_PARAMETER_NAME] = LocalData::getIncludeParameter($filters); $organizationId = $filters['organization'] ?? null; $lecturerId = $filters['lecturer'] ?? null; diff --git a/src/DataProvider/CourseItemDataProvider.php b/src/DataProvider/CourseItemDataProvider.php index a5a9fc281401bfcec9b3de21a242b563312fcf82..18378aa3e35bc48a39c81d7cf6bac722af67337d 100644 --- a/src/DataProvider/CourseItemDataProvider.php +++ b/src/DataProvider/CourseItemDataProvider.php @@ -8,6 +8,7 @@ use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use Dbp\Relay\BaseCourseBundle\API\CourseProviderInterface; use Dbp\Relay\BaseCourseBundle\Entity\Course; +use Dbp\Relay\CoreBundle\LocalData\LocalData; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; final class CourseItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface @@ -32,10 +33,7 @@ final class CourseItemDataProvider extends AbstractController implements ItemDat $options = []; $options['lang'] = $filters['lang'] ?? 'de'; - - if ($include = ($filters['include'] ?? null)) { - $options['include'] = $include; - } + $options[LocalData::INCLUDE_PARAMETER_NAME] = LocalData::getIncludeParameter($filters); return $this->api->getCourseById($id, $options); } diff --git a/src/Entity/Course.php b/src/Entity/Course.php index 02ae535b74054c9347b65d5195e626b44b269918..07071fe6abecc1baf746461bbacab69b3ae83459 100644 --- a/src/Entity/Course.php +++ b/src/Entity/Course.php @@ -19,8 +19,8 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait; * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, * {"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", "required" = false, "type" = "string", "example" = "woody007"}, - * {"name" = "include", "in" = "query", "description" = "Optional resources to include", "type" = "string", "example" = "BaseCourse.code,BaseCourse.numberOfCredits"} + * {"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"} * } * } * } @@ -33,7 +33,7 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait; * "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" = "include", "in" = "query", "description" = "Optional resources 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"} * } * } * } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index ed2c03dc35df573255cc32306816964fd5da6821..a72592008bc461aceb2cb7180365ab7bf5b85f6d 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -9,11 +9,6 @@ services: autowire: true autoconfigure: true -# Dbp\Relay\BaseCourseBundle\Serializer\Normalizer\CourseNormalizer: -# autowire: true -# autoconfigure: true -# tags: ['serializer.normalizer'] - Dbp\Relay\BaseCourseBundle\Service\DummyCourseProvider: autowire: true autoconfigure: true diff --git a/src/Serializer/Normalizer/CourseNormalizer.php b/src/Serializer/Normalizer/CourseNormalizer.php deleted file mode 100644 index d9d69fced474948b63d4553c0d1f8f1240c96606..0000000000000000000000000000000000000000 --- a/src/Serializer/Normalizer/CourseNormalizer.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BaseCourseBundle\Serializer\Normalizer; - -use Dbp\Relay\BaseCourseBundle\Entity\Course; -use Symfony\Component\Serializer\Exception\ExceptionInterface; -use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; -use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; -use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; - -class CourseNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface -{ - use NormalizerAwareTrait; - - private const ALREADY_CALLED = 'COURSE_NORMALIZER_CURRENT_USER_ALREADY_CALLED'; - - /** - * @return array|string|int|float|bool|\ArrayObject|null - * - * @throws ExceptionInterface - */ - public function normalize($object, $format = null, array $context = []) - { - // TODO: only add localData group if it is requested? - // problem: $context['filters'] not available at this point - $context['groups'][] = 'BaseCourse:localData'; - $context[self::ALREADY_CALLED] = true; - - return $this->normalizer->normalize($object, $format, $context); - } - - public function supportsNormalization($data, $format = null, array $context = []): bool - { - if (isset($context[self::ALREADY_CALLED])) { - return false; - } - - return $data instanceof Course; - } -}