From 513fb6111dcd7f8afa5499fc1214906a3e597e83 Mon Sep 17 00:00:00 2001 From: Tobias Gross-Vogt <tgros@tugraz.at> Date: Thu, 10 Feb 2022 12:28:29 +0100 Subject: [PATCH] reintroducing CourseAttendee --- composer.json | 1 + composer.lock | 56 ++++++++++++++++++++++- src/API/CourseProviderInterface.php | 6 +++ src/Controller/GetAttendeesByCourse.php | 39 ++++++++++++++++ src/Entity/CourseAttendee.php | 59 +++++++++++++++++++++++++ src/Service/DummyCourseProvider.php | 12 +++++ 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/Controller/GetAttendeesByCourse.php create mode 100644 src/Entity/CourseAttendee.php diff --git a/composer.json b/composer.json index bf23ed6..1a88b54 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "php": ">=7.3", "ext-json": "*", "api-platform/core": "^2.6", + "dbp/relay-base-person-bundle": "dev-main", "dbp/relay-core-bundle": "^0.1.11", "symfony/framework-bundle": "^5.4" }, diff --git a/composer.lock b/composer.lock index efdbe14..94a8fb3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f5c22688f47ec610c9b3ebcd5797cb1b", + "content-hash": "c6de62624b6c871ceea7cd39f50c97b9", "packages": [ { "name": "api-platform/core", @@ -167,6 +167,56 @@ ], "time": "2022-01-11T10:29:54+00:00" }, + { + "name": "dbp/relay-base-person-bundle", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-person-bundle", + "reference": "2c871dbc1774839a10f544dc44a2e54d0a525443" + }, + "require": { + "api-platform/core": "^2.6.3", + "dbp/relay-core-bundle": "^0.1.25", + "ext-json": "*", + "guzzlehttp/guzzle": "^7.0", + "nelmio/cors-bundle": "^2.1.0", + "php": ">=7.3", + "phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", + "symfony/config": "^5.2", + "symfony/expression-language": "^5.2", + "symfony/framework-bundle": "^5.2", + "symfony/security-bundle": "^5.2", + "symfony/security-core": "^5.2", + "symfony/security-guard": "^5.2", + "symfony/twig-bundle": "^5.2", + "symfony/validator": "^5.2", + "symfony/yaml": "^5.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.0.0", + "phpunit/phpunit": "^9", + "symfony/browser-kit": "^5.2", + "symfony/http-client": "^5.2", + "symfony/monolog-bundle": "^3.7", + "symfony/phpunit-bridge": "^5.2", + "vimeo/psalm": "^4.4" + }, + "default-branch": true, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Dbp\\Relay\\BasePersonBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "time": "2022-02-07T09:07:33+00:00" + }, { "name": "dbp/relay-core-bundle", "version": "v0.1.30", @@ -9917,7 +9967,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "dbp/relay-base-person-bundle": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/API/CourseProviderInterface.php b/src/API/CourseProviderInterface.php index b21e4ab..00c9856 100644 --- a/src/API/CourseProviderInterface.php +++ b/src/API/CourseProviderInterface.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Dbp\Relay\CourseBundle\API; use Dbp\Relay\CourseBundle\Entity\Course; +use Dbp\Relay\CourseBundle\Entity\CourseAttendee; interface CourseProviderInterface { @@ -19,4 +20,9 @@ interface CourseProviderInterface * @return Course[] */ public function getCoursesByOrganization(string $orgUnitId, array $options = []): array; + + /** + * @return CourseAttendee[] + */ + public function getAttendeesByCourse(string $courseId, array $options = []): array; } diff --git a/src/Controller/GetAttendeesByCourse.php b/src/Controller/GetAttendeesByCourse.php new file mode 100644 index 0000000..66a382e --- /dev/null +++ b/src/Controller/GetAttendeesByCourse.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\CourseBundle\Controller; + +use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; +use Dbp\Relay\CourseBundle\API\CourseProviderInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; + +class GetStudentsByCourse extends AbstractController +{ + public const ITEMS_PER_PAGE = 250; + + protected $coursesProvider; + + public function __construct(CourseProviderInterface $coursesProvider) + { + $this->coursesProvider = $coursesProvider; + } + + public function __invoke(string $identifier, Request $request): ArrayFullPaginator + { + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); + + $page = (int) $request->query->get('page', 1); + $perPage = (int) $request->query->get('perPage', self::ITEMS_PER_PAGE); + + $options = []; + if ($request->query->has('lang')) { + $options['lang'] = (string) $request->query->get('lang'); + } + + $courses = $this->coursesProvider->getAttendeesByCourse($identifier, $options); + + return new ArrayFullPaginator($courses, $page, $perPage); + } +} diff --git a/src/Entity/CourseAttendee.php b/src/Entity/CourseAttendee.php new file mode 100644 index 0000000..ab23418 --- /dev/null +++ b/src/Entity/CourseAttendee.php @@ -0,0 +1,59 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\CourseBundle\Entity; + +use ApiPlatform\Core\Annotation\ApiResource; +use Dbp\Relay\BasePersonBundle\Controller\GetAtteendeesByCourse; +use Dbp\Relay\BasePersonBundle\Entity\PersonInterface; +use Dbp\Relay\BasePersonBundle\Entity\PersonTrait; +use Symfony\Component\Serializer\Annotation\Groups; + +/** + * @ApiResource( + * collectionOperations={ + * "get" = { + * "openapi_context" = { + * "tags" = {"Courses"} + * } + * }, + * "get_bycourse" = { + * "method" = "GET", + * "path" = "/courses/{identifier}/attendees", + * "controller" = GetAtteendeesByCourse::class, + * "read" = false, + * "normalization_context" = { + * "jsonld_embed_context" = true, + * "groups" = {"BasePerson:output"} + * }, + * "openapi_context" = { + * "tags" = {"Courses"}, + * "summary" = "Get the attendees of a course.", + * "parameters" = { + * {"name" = "identifier", "in" = "path", "description" = "Id of course", "required" = true, "type" = "string", "example" = "123456"}, + * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"} + * } + * } + * } + * }, + * itemOperations={ + * "get" = { + * "openapi_context" = { + * "tags" = {"Courses"} + * } + * } + * }, + * iri="http://schema.org/Person", + * shortName="BasePerson", + * description="A person of the LDAP system", + * normalizationContext={ + * "groups" = {"BasePerson:output"}, + * "jsonld_embed_context" = true, + * } + * ) + */ +class CourseAttendee implements PersonInterface +{ + use PersonTrait; +} diff --git a/src/Service/DummyCourseProvider.php b/src/Service/DummyCourseProvider.php index 9e9a3f5..c35056c 100644 --- a/src/Service/DummyCourseProvider.php +++ b/src/Service/DummyCourseProvider.php @@ -6,6 +6,7 @@ namespace Dbp\Relay\CourseBundle\Service; use Dbp\Relay\CourseBundle\API\CourseProviderInterface; use Dbp\Relay\CourseBundle\Entity\Course; +use Dbp\Relay\CourseBundle\Entity\CourseAttendee; class DummyCourseProvider implements CourseProviderInterface { @@ -31,4 +32,15 @@ class DummyCourseProvider implements CourseProviderInterface { return $this->getCourses($options); } + + public function getAttendeesByCourse(string $courseId, array $options = []): array + { + $attendee = new CourseAttendee(); + $attendee->setIdentifier('aeinstein'); + $attendee->setGivenName('Albert'); + $attendee->setFamilyName('Einstein'); + $attendee->setEmail('info@einstein.com'); + + return [$attendee]; + } } -- GitLab