-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add delete controller * Update/Delete schedules * Remove unused method * Rename method * Consistency check * Finalize
- Loading branch information
Showing
13 changed files
with
653 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DatabaseException extends AbstractApiException | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
500, | ||
'A database error occurred.' | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Schedule/Attributes/Request/ElementScheduleRequestBody.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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\Attributes\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Content\ItemsJson; | ||
use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\UpdateSchedule; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ElementScheduleRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new ItemsJson(UpdateSchedule::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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; | ||
|
||
use OpenApi\Attributes\Delete; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\DatabaseException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\IdJson; | ||
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\Service\ScheduleServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DeleteController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly ScheduleServiceInterface $scheduleService | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementNotFoundException|DatabaseException | ||
*/ | ||
#[Route('/schedules/{id}', name: 'pimcore_studio_api_delete_schedule', methods: ['DELETE'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[Delete( | ||
path: self::API_PATH . '/schedules/{id}', | ||
operationId: 'deleteSchedule', | ||
summary: 'Delete schedule with given id', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Schedule->name] | ||
)] | ||
#[IdParameter(type: 'schedule', schema: new Schema(type: 'integer', example: 123))] | ||
#[SuccessResponse( | ||
description: 'Id of deleted schedule', | ||
content: new IdJson('ID of deleted schedule') | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function deleteSchedule(int $id): JsonResponse | ||
{ | ||
$this->scheduleService->deleteSchedule($id); | ||
|
||
return $this->jsonResponse(['id' => $id]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\JsonContent; | ||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotAuthorizedException; | ||
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\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 Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CreateController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly ScheduleServiceInterface $scheduleService | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws NotAuthorizedException|ElementNotFoundException | ||
*/ | ||
#[Route('/schedules/{elementType}/{id}', name: 'pimcore_studio_api_create_schedule', methods: ['POST'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[POST( | ||
path: self::API_PATH . '/schedules/{elementType}/{id}', | ||
operationId: 'createSchedule', | ||
summary: 'Create schedule for element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Schedule->name] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[SuccessResponse( | ||
description: 'Created schedule', | ||
content: new JsonContent(ref: Schedule::class) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
])] | ||
public function createSchedule(string $elementType, int $id): JsonResponse | ||
{ | ||
return $this->jsonResponse($this->scheduleService->createSchedule($elementType, $id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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\Put; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\DatabaseException; | ||
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\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Schedule\Attributes\Request\ElementScheduleRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Schedule\Request\UpdateElementSchedules; | ||
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\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UpdateController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly ScheduleServiceInterface $scheduleService | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws DatabaseException | ||
*/ | ||
#[Route('/schedules/{elementType}/{id}', name: 'pimcore_studio_api_update_schedules', methods: ['PUT'])] | ||
#[Put( | ||
path: self::API_PATH . '/schedules/{elementType}/{id}', | ||
operationId: 'updateSchedulesForElementByTypeAndId', | ||
summary: 'Update schedules for an element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Schedule->name] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[ElementScheduleRequestBody] | ||
#[SuccessResponse( | ||
description: 'List of schedules', | ||
content: new ItemsJson(Schedule::class) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND | ||
])] | ||
public function updateSchedules( | ||
string $elementType, | ||
int $id, | ||
#[MapRequestPayload] UpdateElementSchedules $updateElementSchedules | ||
): JsonResponse | ||
{ | ||
$this->scheduleService->updateSchedules($elementType, $id, $updateElementSchedules); | ||
|
||
return $this->jsonResponse(['items' => $this->scheduleService->listSchedules($elementType, $id)]); | ||
} | ||
} |
Oops, something went wrong.