diff --git a/composer.json b/composer.json index 1a88b5456621d482dbfa67ddb2ad5ddd4343f37e..bf23ed66c7baa29a39e0d8f822a443dc6fc72584 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "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 158c78adf0959ea6c5c7a2431f3ef8d131e83cd5..efdbe140d970e40749b13883eb7e64bede7c3136 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": "c6de62624b6c871ceea7cd39f50c97b9", + "content-hash": "f5c22688f47ec610c9b3ebcd5797cb1b", "packages": [ { "name": "api-platform/core", @@ -167,56 +167,6 @@ ], "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": "a7e3c201348fe70841d7e7c031e7a5ca8a007a54" - }, - "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-01-31T11:47:53+00:00" - }, { "name": "dbp/relay-core-bundle", "version": "v0.1.30", @@ -9967,9 +9917,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "dbp/relay-base-person-bundle": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/API/CourseProviderInterface.php b/src/API/CourseProviderInterface.php index a5fc072bf64c5ba8e81377e1bdac1ec347321ad3..b21e4ab226e63a87d2312bdbdc15e5f0b5675853 100644 --- a/src/API/CourseProviderInterface.php +++ b/src/API/CourseProviderInterface.php @@ -4,9 +4,7 @@ declare(strict_types=1); namespace Dbp\Relay\CourseBundle\API; -use Dbp\Relay\BasePersonBundle\Entity\Person; use Dbp\Relay\CourseBundle\Entity\Course; -use Dbp\Relay\CourseBundle\Entity\Exam; interface CourseProviderInterface { @@ -21,19 +19,4 @@ interface CourseProviderInterface * @return Course[] */ public function getCoursesByOrganization(string $orgUnitId, array $options = []): array; - - /** - * @return Course[] - */ - public function getCoursesByPerson(string $personId, array $options = []): array; - - /** - * @return Person[] - */ - public function getStudentsByCourse(string $courseId, array $options = []): array; - - /** - * @return Exam[] - */ - public function getExamsByCourse(string $courseId, array $options = []): array; } diff --git a/src/Controller/GetCoursesByOrganization.php b/src/Controller/GetCoursesByOrganization.php index 4b33c0ee2daae3d53ae885f683cb496df6033279..ef9e2ab9a80a4a1772207abf4e69da59d11462c7 100644 --- a/src/Controller/GetCoursesByOrganization.php +++ b/src/Controller/GetCoursesByOrganization.php @@ -27,11 +27,7 @@ class GetCoursesByOrganization extends AbstractController $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'); - } + $options = ['lang' => $request->query->get('lang', 'de')]; $courses = $this->coursesProvider->getCoursesByOrganization($id, $options); diff --git a/src/Controller/GetCoursesByPerson.php b/src/Controller/GetCoursesByPerson.php deleted file mode 100644 index b5c13ab6438b034e2feb61b51f2d64d2e40446e9..0000000000000000000000000000000000000000 --- a/src/Controller/GetCoursesByPerson.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Controller; - -use ApiPlatform\Core\DataProvider\PaginatorInterface; -use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; -use Dbp\Relay\CourseBundle\API\CourseProviderInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\Request; - -class GetCoursesByPerson extends AbstractController -{ - public const ITEMS_PER_PAGE = 250; - - protected $coursesProvider; - - public function __construct(CourseProviderInterface $coursesProvider) - { - $this->coursesProvider = $coursesProvider; - } - - public function __invoke(string $id, Request $request): PaginatorInterface - { - $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->getCoursesByPerson($id, $options); - - return new ArrayFullPaginator($courses, $page, $perPage); - } -} diff --git a/src/Controller/GetExamsByCourse.php b/src/Controller/GetExamsByCourse.php deleted file mode 100644 index ee2413e802002cad21b7c2ff1e60e3600b24541e..0000000000000000000000000000000000000000 --- a/src/Controller/GetExamsByCourse.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Controller; - -use ApiPlatform\Core\DataProvider\PaginatorInterface; -use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; -use Dbp\Relay\CourseBundle\API\CourseProviderInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\Request; - -class GetExamsByCourse extends AbstractController -{ - public const ITEMS_PER_PAGE = 250; - - protected $coursesProvider; - - public function __construct(CourseProviderInterface $coursesProvider) - { - $this->coursesProvider = $coursesProvider; - } - - public function __invoke(string $id, Request $request): PaginatorInterface - { - $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->getExamsByCourse($id, $options); - - return new ArrayFullPaginator($courses, $page, $perPage); - } -} diff --git a/src/Controller/GetStudentsByCourse.php b/src/Controller/GetStudentsByCourse.php deleted file mode 100644 index 827e1cfa61d8345423140170f6966f0350e59120..0000000000000000000000000000000000000000 --- a/src/Controller/GetStudentsByCourse.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Controller; - -use ApiPlatform\Core\DataProvider\PaginatorInterface; -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 $id, Request $request): PaginatorInterface - { - $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->getStudentsByCourse($id, $options); - - return new ArrayFullPaginator($courses, $page, $perPage); - } -} diff --git a/src/DataProvider/CourseCollectionDataProvider.php b/src/DataProvider/CourseCollectionDataProvider.php index 5e55ecad7447de4e4e6b3e399f03ce0c3ff8ceb4..d4a01d0b6d8f97f954ea6aab8d53c347e499551b 100644 --- a/src/DataProvider/CourseCollectionDataProvider.php +++ b/src/DataProvider/CourseCollectionDataProvider.php @@ -27,17 +27,21 @@ final class CourseCollectionDataProvider extends AbstractController implements C public function getCollection(string $resourceClass, string $operationName = null, array $context = []): ArrayFullPaginator { - $perPage = 30; - $page = 1; + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $filters = $context['filters'] ?? []; + $options = ['lang' => $filters['lang'] ?? 'de']; + + $page = 1; if (isset($filters['page'])) { $page = (int) $filters['page']; } + + $perPage = 30; if (isset($filters['perPage'])) { $perPage = (int) $filters['perPage']; } - return new ArrayFullPaginator($this->api->getCourses(), $page, $perPage); + return new ArrayFullPaginator($this->api->getCourses($options), $page, $perPage); } } diff --git a/src/DataProvider/CourseItemDataProvider.php b/src/DataProvider/CourseItemDataProvider.php index 066fae77c81da0c6c9f5e1de2fef3591c126de90..d494724b85c5c5279d4cf1d68e89e5f09a8ac9d3 100644 --- a/src/DataProvider/CourseItemDataProvider.php +++ b/src/DataProvider/CourseItemDataProvider.php @@ -26,6 +26,11 @@ final class CourseItemDataProvider extends AbstractController implements ItemDat public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Course { - return $this->api->getCourseById($id); + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); + + $filters = $context['filters'] ?? []; + $options = ['lang' => $filters['lang'] ?? 'de']; + + return $this->api->getCourseById($id, $options); } } diff --git a/src/Entity/Course.php b/src/Entity/Course.php index 4d018ad732cba84d1a84f2e7ffe17708a2ecc076..fbeae68468cd033a37f6bc61834b2172d2209bb5 100644 --- a/src/Entity/Course.php +++ b/src/Entity/Course.php @@ -6,6 +6,7 @@ namespace Dbp\Relay\CourseBundle\Entity; use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; +use Dbp\Relay\CourseBundle\Controller\GetCoursesByOrganization; use Symfony\Component\Serializer\Annotation\Groups; /** @@ -33,20 +34,6 @@ use Symfony\Component\Serializer\Annotation\Groups; * } * }, * }, - * "get_byperson" = { - * "method" = "GET", - * "path" = "/base/people/{id}/courses", - * "controller" = GetCoursesByPerson::class, - * "read" = false, - * "openapi_context" = { - * "tags" = {"Courses"}, - * "summary" = "Get the Courses related to a person.", - * "parameters" = { - * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, - * {"name" = "id", "in" = "path", "description" = "Id of Organization", "required" = true, "type" = "string", "example" = "123456"} - * } - * }, - * }, * }, * itemOperations={ * "get" = { diff --git a/src/Entity/CourseAttendee.php b/src/Entity/CourseAttendee.php deleted file mode 100644 index 6b375661fc25c25ad176e45d7baf41b9b0a0d6fd..0000000000000000000000000000000000000000 --- a/src/Entity/CourseAttendee.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Entity; - -use ApiPlatform\Core\Annotation\ApiResource; -use Dbp\Relay\BasePersonBundle\Entity\PersonTrait; - -/** - * @ApiResource( - * collectionOperations={ - * "get_bycourse" = { - * "method" = "GET", - * "path" = "/courses/{id}/attendees", - * "controller" = GetStudentsByCourse::class, - * "read" = false, - * "openapi_context" = { - * "tags" = {"Courses"}, - * "summary" = "Get the attendees attending to a course.", - * "parameters" = { - * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, - * {"name" = "id", "in" = "path", "description" = "Id of Organization", "required" = true, "type" = "string", "example" = "123456"} - * } - * }, - * } - * }, - * itemOperations={}, - * iri="https://schema.org/EducationEvent", - * normalizationContext={"groups" = {"BasePerson:output"}, "jsonld_embed_context" = true}, - * denormalizationContext={"groups" = {"BasePerson:input"}, "jsonld_embed_context" = true} - * ) - */ -class CourseAttendee -{ - use PersonTrait; -} diff --git a/src/Entity/Exam.php b/src/Entity/Exam.php deleted file mode 100644 index d97cc3782b78e788182971b90c573f12392e3fc0..0000000000000000000000000000000000000000 --- a/src/Entity/Exam.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Entity; - -use ApiPlatform\Core\Annotation\ApiProperty; -use ApiPlatform\Core\Annotation\ApiResource; -use DateTime; -use DBP\API\CourseBundle\Controller\GetExamsByCourse; -use Symfony\Component\Serializer\Annotation\Groups; - -/** - * @ApiResource( - * collectionOperations={ - * "get_bycourse" = { - * "method" = "GET", - * "path" = "/courses/{id}/exams", - * "controller" = GetExamsByCourse::class, - * "read" = false, - * "openapi_context" = { - * "tags" = {"Courses"}, - * "summary" = "Get the Exams for a course.", - * "parameters" = { - * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, - * {"name" = "id", "in" = "path", "description" = "Id of Organization", "required" = true, "type" = "string", "example" = "123456"} - * } - * }, - * } - * }, - * itemOperations={}, - * iri="https://schema.org/EducationEvent", - * normalizationContext={"groups" = {"Exam:output"}, "jsonld_embed_context" = true}, - * denormalizationContext={"groups" = {"Exam:input"}, "jsonld_embed_context" = true} - * ) - */ -class Exam -{ - /** - * @ApiProperty(identifier=true) - * - * @var string - */ - private $identifier; - - /** - * @ApiProperty(iri="https://schema.org/description") - * @Groups({"Exam:output"}) - * - * @var string - */ - private $description; - - /** - * @ApiProperty(iri="https://schema.org/startDate") - * @Groups({"Exam:output"}) - * - * @var DateTime - */ - private $startDate; - - /** - * @ApiProperty(iri="https://schema.org/endDate") - * @Groups({"Exam:output"}) - * - * @var DateTime - */ - private $endDate; - - /** - * @ApiProperty(iri="https://schema.org/location") - * @Groups({"Exam:output"}) - * - * @var string - */ - private $location; - - public function getIdentifier(): string - { - return $this->identifier; - } - - public function setIdentifier(string $identifier): void - { - $this->identifier = $identifier; - } - - public function getDescription(): string - { - return $this->description; - } - - public function setDescription(string $description): void - { - $this->description = $description; - } - - public function getStartDate(): DateTime - { - return $this->startDate; - } - - public function setStartDate(DateTime $startDate): void - { - $this->startDate = $startDate; - } - - public function getEndDate(): DateTime - { - return $this->endDate; - } - - public function setEndDate(DateTime $endDate): void - { - $this->endDate = $endDate; - } - - public function getLocation(): string - { - return $this->location; - } - - public function setLocation(string $location): void - { - $this->location = $location; - } -} diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index fcfc0a10c332731b4e754ced0452397ac69d3a82..62573e7d6a4169a70cd61954fe23ed008b46c6a0 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,30 +1,17 @@ services: - Dbp\Relay\CourseBundle\Command\TestCommand: - autowire: true - autoconfigure: true - Dbp\Relay\CourseBundle\Controller\: resource: '../../Controller' autoconfigure: true autowire: true - Dbp\Relay\CourseBundle\DataPersister\: - resource: '../../DataPersister' - autowire: true - autoconfigure: true - Dbp\Relay\CourseBundle\DataProvider\: resource: '../../DataProvider' autowire: true autoconfigure: true - Dbp\Relay\CourseBundle\Service\ExternalApi: - autowire: true - autoconfigure: true - - Dbp\Relay\CourseBundle\Service\MyCustomService: + Dbp\Relay\CourseBundle\Service\DummyCourseProvider: autowire: true autoconfigure: true - Dbp\Relay\CourseBundle\Service\CourseProviderInterface: - '@Dbp\Relay\CourseBundle\Service\ExternalApi' + Dbp\Relay\CourseBundle\API\CourseProviderInterface: + '@Dbp\Relay\CourseBundle\Service\DummyCourseProvider' diff --git a/src/Service/DummyCourseProvider.php b/src/Service/DummyCourseProvider.php index 876ed28612adb73e18e3432d33b53380bcd6c9a2..9e9a3f5f791eaeabb558f4f796a26138c3e46f4f 100644 --- a/src/Service/DummyCourseProvider.php +++ b/src/Service/DummyCourseProvider.php @@ -4,11 +4,8 @@ declare(strict_types=1); namespace Dbp\Relay\CourseBundle\Service; -use DateTime; -use Dbp\Relay\BasePersonBundle\Entity\Person; use Dbp\Relay\CourseBundle\API\CourseProviderInterface; use Dbp\Relay\CourseBundle\Entity\Course; -use Dbp\Relay\CourseBundle\Entity\Exam; class DummyCourseProvider implements CourseProviderInterface { @@ -34,33 +31,4 @@ class DummyCourseProvider implements CourseProviderInterface { return $this->getCourses($options); } - - public function getCoursesByPerson(string $personId, array $options = []): array - { - return $this->getCourses($options); - } - - public function getStudentsByCourse(string $courseId, array $options = []): array - { - $person = new Person(); - $person->setIdentifier('123'); - $person->setFamilyName('Spencer'); - $person->setGivenName('Bud'); - $person->setEmail('bud@spencer.net'); - $person->setBirthDate('1.1.1950'); - - return [$person]; - } - - public function getExamsByCourse(string $courseId, array $options = []): array - { - $exam = new Exam(); - $exam->setIdentifier('123'); - $exam->setDescription('Oral exam'); - $exam->setStartDate(new DateTime('25.08.2021 8:00AM')); - $exam->setEndDate(new DateTime('25.08.2021 10:00AM')); - $exam->setLocation('In a room'); - - return [$exam]; - } } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index b0721d979f977fd5cd6336bed616dde8d6c1bc9f..553e39f4566cafefebce57aa4042adb59722c858 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -9,32 +9,17 @@ use Symfony\Component\HttpFoundation\Response; class ApiTest extends ApiTestCase { - public function testBasics() + public function testCoursesNoAuth() { $client = self::createClient(); - $response = $client->request('GET', '/course/courses'); - $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); - - $response = $client->request('GET', '/course/courses/graz'); - $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); - - $response = $client->request('DELETE', '/course/courses/graz'); - $this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); - - $response = $client->request('PUT', '/course/courses/graz', [ - 'headers' => [ - 'Content-Type' => 'application/json', - ], - 'body' => json_encode(['name' => 'foo']), - ]); - $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); - $this->assertSame('foo', json_decode($response->getContent(), true)['name']); + $response = $client->request('GET', '/courses'); + $this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode()); } - public function testNoAuth() + public function testCourseNoAuth() { $client = self::createClient(); - $response = $client->request('GET', '/course/courses/graz/loggedin-only'); + $response = $client->request('GET', '/courses/123'); $this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode()); } } diff --git a/tests/Kernel.php b/tests/Kernel.php index 16a2d3da9efd5d48c5e69e5b72d74b5fa9fa8e4e..988dcbd70eac5dbaf15810b6a8c3e0c095fcfb0e 100644 --- a/tests/Kernel.php +++ b/tests/Kernel.php @@ -46,9 +46,5 @@ class Kernel extends BaseKernel 'test' => true, 'secret' => '', ]); - - $container->extension('dbp_relay_course', [ - 'example_config' => 'test-42', - ]); } } diff --git a/tests/Service/ExternalApiTest.php b/tests/Service/ExternalApiTest.php deleted file mode 100644 index 13f1f9b10ff8ff3f0bacd67aa38f236d782ccb2d..0000000000000000000000000000000000000000 --- a/tests/Service/ExternalApiTest.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\CourseBundle\Tests\Service; - -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; - -class ExternalApiTest extends WebTestCase -{ - protected function setUp(): void - { - } - - public function test() - { - } -}