diff --git a/src/DataProvider/CourseCollectionDataProvider.php b/src/DataProvider/CourseCollectionDataProvider.php index 421d1fd5f45f115948c7aa2f6ff2015bc57b06c9..62f0d342bd549a4b53a7230dc1413d4012b4a7fc 100644 --- a/src/DataProvider/CourseCollectionDataProvider.php +++ b/src/DataProvider/CourseCollectionDataProvider.php @@ -8,8 +8,10 @@ use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use Dbp\Relay\BaseCourseBundle\API\CourseProviderInterface; use Dbp\Relay\BaseCourseBundle\Entity\Course; +use Dbp\Relay\CoreBundle\Exception\ApiError; use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; final class CourseCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface { @@ -29,24 +31,33 @@ final class CourseCollectionDataProvider extends AbstractController implements C { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); - $options = []; $filters = $context['filters'] ?? []; + + $options = []; $options['lang'] = $filters['lang'] ?? 'de'; - $term = $filters['term'] ?? null; - if ($term !== null) { + + if ($term = ($filters['term'] ?? null)) { $options['term'] = $term; } - $organizationId = $filters['organizationId'] ?? null; - $personId = $filters['personId'] ?? null; + if ($include = ($filters['include'] ?? null)) { + if ($include === 'localData') { + $options['includeLocalData'] = true; + } else { + throw new ApiError(Response::HTTP_BAD_REQUEST, 'requested inclusion of unknown resource '.$include); + } + } + + $organizationId = $filters['organization'] ?? null; + $lecturerId = $filters['lecturer'] ?? null; $courses = null; - if (!empty($organizationId) || !empty($personId)) { + if (!empty($organizationId) || !empty($lecturerId)) { if (!empty($organizationId)) { $courses = $this->courseProvider->getCoursesByOrganization($organizationId, $options); } - if (!empty($personId)) { - $coursesByPerson = $this->courseProvider->getCoursesByPerson($personId, $options); + if (!empty($lecturerId)) { + $coursesByPerson = $this->courseProvider->getCoursesByPerson($lecturerId, $options); if (!empty($organizationId)) { $courses = array_uintersect($courses, $coursesByPerson, 'Dbp\Relay\BaseCourseBundle\DataProvider\CourseCollectionDataProvider::compareCourses'); diff --git a/src/DependencyInjection/DbpRelayBaseCourseExtension.php b/src/DependencyInjection/DbpRelayBaseCourseExtension.php index fcc750dd76143f80af98f5f98f4e7cdf93e20356..38c2e02e3fe5e2a963b495ed5971f20d5222bb6a 100644 --- a/src/DependencyInjection/DbpRelayBaseCourseExtension.php +++ b/src/DependencyInjection/DbpRelayBaseCourseExtension.php @@ -16,6 +16,12 @@ class DbpRelayBaseCourseExtension extends ConfigurableExtension $this->extendArrayParameter( $container, 'api_platform.resource_class_directories', [__DIR__.'/../Entity']); + $this->extendArrayParameter( + $container, 'dbp_api.paths_to_hide', [ + '/course_attendees', + '/course_attendees/{identifier}', + ]); + $loader = new YamlFileLoader( $container, new FileLocator(__DIR__.'/../Resources/config') diff --git a/src/Entity/Course.php b/src/Entity/Course.php index 7b419e8953663854120415525ab264ca431ec607..258a4c67a2c396b6823eaeebf9addfdf8f4571c3 100644 --- a/src/Entity/Course.php +++ b/src/Entity/Course.php @@ -17,8 +17,9 @@ use Symfony\Component\Serializer\Annotation\Groups; * "parameters" = { * {"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" = "organizationId", "in" = "query", "description" = "ID of organization", "required" = false, "type" = "string", "example" = "1190"}, - * {"name" = "personId", "in" = "query", "description" = "ID of lecturer", "required" = false, "type" = "string", "example" = "woody007"}, + * {"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" = "localData"} * } * } * } @@ -29,9 +30,9 @@ use Symfony\Component\Serializer\Annotation\Groups; * "openapi_context" = { * "tags" = {"BaseCourse"}, * "parameters" = { - * {"name" = "identifier", "in" = "path", "description" = "Id of course", "required" = true, "type" = "string", "example" = "257571"}, + * {"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" = "localData"} + * {"name" = "include", "in" = "query", "description" = "Optional resources to include", "type" = "string", "example" = "localData"} * } * } * } diff --git a/src/Entity/CourseAttendee.php b/src/Entity/CourseAttendee.php index 676e60837994b22c7f674d18728f2368f26ed2e2..9723dde5ea7ca36c93ff4c8df1d5f251c681c832 100644 --- a/src/Entity/CourseAttendee.php +++ b/src/Entity/CourseAttendee.php @@ -34,7 +34,7 @@ use Symfony\Component\Serializer\Annotation\Groups; * "tags" = {"BaseCourse"}, * "summary" = "Get the attendees of a course.", * "parameters" = { - * {"name" = "identifier", "in" = "path", "description" = "Id of course", "required" = true, "type" = "string", "example" = "123456"}, + * {"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"} * } * }