From 06c1489496cc3080659c84dc167d55c16c4bcf8d Mon Sep 17 00:00:00 2001 From: Matthias Schuhmayer <38959016+mattamon@users.noreply.github.com> Date: Thu, 23 May 2024 17:12:54 +0200 Subject: [PATCH] [Feature] Add initial controllers and services, schemas etc. (#74) * Add initial controllers and services, schemas etc. * Apply php-cs-fixer changes * Consistency check * Add declare strict --------- Co-authored-by: mattamon --- config/schedules.yaml | 22 +++++ .../PimcoreStudioBackendExtension.php | 1 + .../Element/CollectionController.php | 2 +- src/OpenApi/Config/Tags.php | 5 ++ .../Element/CollectionController.php | 79 +++++++++++++++++ src/Schedule/Event/ScheduleEvent.php | 39 ++++++++ src/Schedule/Hydrator/ScheduleHydrator.php | 39 ++++++++ .../Hydrator/ScheduleHydratorInterface.php | 28 ++++++ .../Repository/ScheduleRepository.php | 40 +++++++++ .../ScheduleRepositoryInterface.php | 22 +++++ src/Schedule/Schema/Schedule.php | 88 +++++++++++++++++++ src/Schedule/Service/ScheduleService.php | 60 +++++++++++++ .../Service/ScheduleServiceInterface.php | 25 ++++++ 13 files changed, 449 insertions(+), 1 deletion(-) create mode 100644 config/schedules.yaml create mode 100644 src/Schedule/Controller/Element/CollectionController.php create mode 100644 src/Schedule/Event/ScheduleEvent.php create mode 100644 src/Schedule/Hydrator/ScheduleHydrator.php create mode 100644 src/Schedule/Hydrator/ScheduleHydratorInterface.php create mode 100644 src/Schedule/Repository/ScheduleRepository.php create mode 100644 src/Schedule/Repository/ScheduleRepositoryInterface.php create mode 100644 src/Schedule/Schema/Schedule.php create mode 100644 src/Schedule/Service/ScheduleService.php create mode 100644 src/Schedule/Service/ScheduleServiceInterface.php diff --git a/config/schedules.yaml b/config/schedules.yaml new file mode 100644 index 000000000..0865db77e --- /dev/null +++ b/config/schedules.yaml @@ -0,0 +1,22 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Schedule\Controller\: + resource: '../src/Schedule/Controller' + public: true + tags: [ 'controller.service_arguments' ] + + Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleService + + Pimcore\Bundle\StudioBackendBundle\Schedule\Repository\ScheduleRepositoryInterface: + class: Pimcore\Bundle\StudioBackendBundle\Schedule\Repository\ScheduleRepository + + Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator\ScheduleHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator\ScheduleHydrator + diff --git a/src/DependencyInjection/PimcoreStudioBackendExtension.php b/src/DependencyInjection/PimcoreStudioBackendExtension.php index eabba6d42..e0065f452 100644 --- a/src/DependencyInjection/PimcoreStudioBackendExtension.php +++ b/src/DependencyInjection/PimcoreStudioBackendExtension.php @@ -63,6 +63,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('notes.yaml'); $loader->load('open_api.yaml'); $loader->load('properties.yaml'); + $loader->load('schedules.yaml'); $loader->load('security.yaml'); $loader->load('services.yaml'); $loader->load('settings.yaml'); diff --git a/src/Note/Controller/Element/CollectionController.php b/src/Note/Controller/Element/CollectionController.php index e82dba34d..2c4130ddb 100644 --- a/src/Note/Controller/Element/CollectionController.php +++ b/src/Note/Controller/Element/CollectionController.php @@ -76,7 +76,7 @@ public function __construct( #[FilterParameter('notes')] #[FieldFilterParameter] #[SuccessResponse( - description: 'Paginated assets with total count as header param', + description: 'Paginated notes with total count as header param', content: new CollectionJson(new NoteCollection()) )] #[DefaultResponses([ diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index 1b22d6905..e3b64e1f5 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -57,6 +57,10 @@ name: Tags::Translation->name, description: 'Get translations either for a single key or multiple keys' )] +#[Tag( + name: Tags::Schedule->name, + description: 'Get schedules for an element' +)] #[Tag( name: Tags::Settings->name, description: 'Get Settings' @@ -80,6 +84,7 @@ enum Tags: string case NotesForElement = 'Notes for Element'; case Properties = 'Properties'; case PropertiesForElement = 'Properties for Element'; + case Schedule = 'Schedule'; case Settings = 'Settings'; case Translation = 'Translation'; case Versions = 'Versions'; diff --git a/src/Schedule/Controller/Element/CollectionController.php b/src/Schedule/Controller/Element/CollectionController.php new file mode 100644 index 000000000..4b0ad9526 --- /dev/null +++ b/src/Schedule/Controller/Element/CollectionController.php @@ -0,0 +1,79 @@ +name] + )] + #[ElementTypeParameter] + #[IdParameter(type: 'element')] + #[SuccessResponse( + description: 'Paginated schedules', + content: new ItemsJson(Schedule::class) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND + ])] + public function getSchedules( + string $elementType, + int $id + ): JsonResponse + { + $tasks = $this->scheduleService->listSchedules($elementType, $id); + + return $this->jsonResponse(['items' => $tasks]); + } +} diff --git a/src/Schedule/Event/ScheduleEvent.php b/src/Schedule/Event/ScheduleEvent.php new file mode 100644 index 000000000..46941d916 --- /dev/null +++ b/src/Schedule/Event/ScheduleEvent.php @@ -0,0 +1,39 @@ +schedule; + } +} diff --git a/src/Schedule/Hydrator/ScheduleHydrator.php b/src/Schedule/Hydrator/ScheduleHydrator.php new file mode 100644 index 000000000..b6a439a4e --- /dev/null +++ b/src/Schedule/Hydrator/ScheduleHydrator.php @@ -0,0 +1,39 @@ +getId(), + $task->getCtype(), + $task->getDate(), + $task->getAction(), + $task->getVersion(), + $task->getActive(), + $task->getUserId() + ); + } +} diff --git a/src/Schedule/Hydrator/ScheduleHydratorInterface.php b/src/Schedule/Hydrator/ScheduleHydratorInterface.php new file mode 100644 index 000000000..d54d05d5e --- /dev/null +++ b/src/Schedule/Hydrator/ScheduleHydratorInterface.php @@ -0,0 +1,28 @@ + + */ + public function listSchedules(string $elementType, int $id): array + { + return $this->getElement($this->serviceResolver, $elementType, $id)->getScheduledTasks(); + } +} diff --git a/src/Schedule/Repository/ScheduleRepositoryInterface.php b/src/Schedule/Repository/ScheduleRepositoryInterface.php new file mode 100644 index 000000000..dab660a6c --- /dev/null +++ b/src/Schedule/Repository/ScheduleRepositoryInterface.php @@ -0,0 +1,22 @@ +id; + } + + public function getCtype(): string + { + return $this->ctype; + } + + public function getDate(): int + { + return $this->date; + } + + public function getAction(): string + { + return $this->action; + } + + public function getVersion(): int + { + return $this->version; + } + + public function isActive(): bool + { + return $this->active; + } + + public function getUserId(): int + { + return $this->userId; + } +} diff --git a/src/Schedule/Service/ScheduleService.php b/src/Schedule/Service/ScheduleService.php new file mode 100644 index 000000000..7c63b550d --- /dev/null +++ b/src/Schedule/Service/ScheduleService.php @@ -0,0 +1,60 @@ + + */ + public function listSchedules(string $elementType, int $id): array + { + $tasks = $this->scheduleRepository->listSchedules($elementType, $id); + + $schedules = []; + + foreach ($tasks as $task) { + $schedule = $this->scheduleHydrator->hydrate($task); + + $this->eventDispatcher->dispatch( + new ScheduleEvent($schedule), + ScheduleEvent::EVENT_NAME + ); + + $schedules[] = $schedule; + } + + return $schedules; + } +} diff --git a/src/Schedule/Service/ScheduleServiceInterface.php b/src/Schedule/Service/ScheduleServiceInterface.php new file mode 100644 index 000000000..d55297455 --- /dev/null +++ b/src/Schedule/Service/ScheduleServiceInterface.php @@ -0,0 +1,25 @@ +