Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add initial controllers and services, schemas etc. #74

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/schedules.yaml
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions src/DependencyInjection/PimcoreStudioBackendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Note/Controller/Element/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
5 changes: 5 additions & 0 deletions src/OpenApi/Config/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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';
Expand Down
79 changes: 79 additions & 0 deletions src/Schedule/Controller/Element/CollectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Controller\Element;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Response\Property\NoteCollection;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Content\ItemsJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class CollectionController extends AbstractApiController
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private readonly ScheduleServiceInterface $scheduleService
)
{
parent::__construct($serializer);
}

#[Route('/schedules/{elementType}/{id}', name: 'pimcore_studio_api_get_element_schedules', methods: ['GET'])]
#[Get(
path: self::API_PATH . '/schedules/{elementType}/{id}',
operationId: 'getSchedulesForElementByTypeAndId',
summary: 'Get schedules for an element',
security: self::SECURITY_SCHEME,
tags: [Tags::Schedule->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]);
}
}
39 changes: 39 additions & 0 deletions src/Schedule/Event/ScheduleEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;

final class ScheduleEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.schedule';
public function __construct(
private readonly Schedule $schedule
)
{
parent::__construct($schedule);
}

/**
* Use this to get additional infos out of the response object
*/
public function getSchedule(): Schedule
{
return $this->schedule;
}
}
39 changes: 39 additions & 0 deletions src/Schedule/Hydrator/ScheduleHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Model\Schedule\Task;

/**
* @internal
*/
final class ScheduleHydrator implements ScheduleHydratorInterface
{
public function hydrate(Task $task): Schedule
{
return new Schedule(
$task->getId(),
$task->getCtype(),
$task->getDate(),
$task->getAction(),
$task->getVersion(),
$task->getActive(),
$task->getUserId()
);
}
}
28 changes: 28 additions & 0 deletions src/Schedule/Hydrator/ScheduleHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Model\Schedule\Task;

/**
* @internal
*/
interface ScheduleHydratorInterface
{
public function hydrate(Task $task): Schedule;
}
40 changes: 40 additions & 0 deletions src/Schedule/Repository/ScheduleRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Repository;

use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait;
use Pimcore\Model\Schedule\Task;

final readonly class ScheduleRepository implements ScheduleRepositoryInterface
{
use ElementProviderTrait;

public function __construct(private ServiceResolverInterface $serviceResolver)
{

}

/**
* @return array<int, Task>
*/
public function listSchedules(string $elementType, int $id): array
{
return $this->getElement($this->serviceResolver, $elementType, $id)->getScheduledTasks();
}
}
22 changes: 22 additions & 0 deletions src/Schedule/Repository/ScheduleRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Repository;

interface ScheduleRepositoryInterface
{
public function listSchedules(string $elementType, int $id): array;
}
Loading
Loading