From f35a21b0152788dbb421ed0cb3db3afc2bc03a03 Mon Sep 17 00:00:00 2001
From: Tobias Gross-Vogt <tgros@tugraz.at>
Date: Thu, 28 Apr 2022 13:01:33 +0200
Subject: [PATCH] include -> includeLocal

---
 composer.lock                                 |  4 +-
 .../CourseCollectionDataProvider.php          |  5 +--
 src/DataProvider/CourseItemDataProvider.php   |  6 +--
 src/Entity/Course.php                         |  6 +--
 src/Resources/config/services.yaml            |  5 ---
 .../Normalizer/CourseNormalizer.php           | 42 -------------------
 6 files changed, 9 insertions(+), 59 deletions(-)
 delete mode 100644 src/Serializer/Normalizer/CourseNormalizer.php

diff --git a/composer.lock b/composer.lock
index af40650..989ddeb 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 1c631d8..ae55b07 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 a5a9fc2..18378aa 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 02ae535..07071fe 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 ed2c03d..a725920 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 d9d69fc..0000000
--- 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;
-    }
-}
-- 
GitLab