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

Changed rest routes pattern #11

Open
wants to merge 2 commits into
base: 1.0
Choose a base branch
from
Open
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
23 changes: 22 additions & 1 deletion src/Controller/QueryFieldRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace EzSystems\EzPlatformQueryFieldType\Controller;

use eZ\Publish\Core\REST\Server\Values\TemporaryRedirect;
use EzSystems\EzPlatformQueryFieldType\API\QueryFieldService;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
Expand All @@ -15,6 +16,7 @@
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\REST\Server\Values\ContentList;
use eZ\Publish\Core\REST\Server\Values\RestContent;
use Symfony\Component\Routing\RouterInterface;

final class QueryFieldRestController
{
Expand All @@ -30,16 +32,21 @@ final class QueryFieldRestController
/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;

/** @var \Symfony\Component\Routing\RouterInterface */
private $router;

public function __construct(
QueryFieldService $queryFieldService,
ContentService $contentService,
ContentTypeService $contentTypeService,
LocationService $locationService
LocationService $locationService,
RouterInterface $router
) {
$this->queryFieldService = $queryFieldService;
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
$this->locationService = $locationService;
$this->router = $router;
}

public function getResults($contentId, $versionNumber, $fieldDefinitionIdentifier): ContentList
Expand All @@ -62,6 +69,20 @@ function (Content $content) {
);
}

public function redirectToResults(int $contentId, string $fieldDefinitionIdentifier)
{
return new TemporaryRedirect(
$this->router->generate(
'ezplatform_ezcontentquery_rest_field_version_items',
[
'contentId' => $contentId,
'versionNumber' => $this->contentService->loadContent($contentId)->versionInfo->versionNo,
'fieldDefinitionIdentifier' => $fieldDefinitionIdentifier,
]
)
);
}

private function getContentType(ContentInfo $contentInfo): ContentType
{
static $contentTypes = [];
Expand Down
15 changes: 12 additions & 3 deletions src/Symfony/Resources/config/routing/rest.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
ezpublish_rest_ezcontentquery_field_results:
path: /api/ezp/v2/content/objects/{contentId}/versions/{versionNumber}/fields/{fieldDefinitionIdentifier}/query/results
ezplatform_ezcontentquery_rest_field_version_items:
path: /api/ezp/v2/content/objects/{contentId}/versions/{versionNumber}/fields/{fieldDefinitionIdentifier}/items
defaults:
_controller: EzSystems\EzPlatformQueryFieldType\Controller\QueryFieldRestController:getResults
methods: [GET]
requirements:
contentId: \d+
fieldId: \d+
versionNumber: \d+
fieldDefinitionIdentifier: \w+

ezplatform_ezcontentquery_rest_field_currentversion_items:
path: /api/ezp/v2/content/objects/{contentId}/currentversion/fields/{fieldDefinitionIdentifier}/items
defaults:
_controller: EzSystems\EzPlatformQueryFieldType\Controller\QueryFieldRestController:redirectToResults
methods: [GET]
requirements:
contentId: \d+
fieldDefinitionIdentifier: \w+