-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-2334: Added remoteId support in export and update processes (#106)
* Moved Export and Content Controllers to REST directory * Fixed download export file route * Added remoteId support for updated content url * Added remoteId support in export * Dropped useless ListParamConverter * Added ContentQueryType * Dropped useless property * Added usage of LoggerAwareInterface in ContentHelper * Removed redundand phpdoc * Added methods to get query based on remoteId or numeric id * Renamed methods to retrieve a query
- Loading branch information
Showing
15 changed files
with
288 additions
and
238 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
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 was deleted.
Oops, something went wrong.
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,110 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzRecommendationClientBundle\Controller\REST; | ||
|
||
use eZ\Publish\API\Repository\Repository; | ||
use eZ\Publish\API\Repository\SearchService; | ||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use EzSystems\EzPlatformRest\Server\Controller as RestController; | ||
use EzSystems\EzPlatformRest\Server\Exceptions\AuthenticationFailedException; | ||
use EzSystems\EzRecommendationClient\Authentication\AuthenticatorInterface; | ||
use EzSystems\EzRecommendationClient\Service\ContentServiceInterface; | ||
use EzSystems\EzRecommendationClient\Value\Content; | ||
use EzSystems\EzRecommendationClient\Value\ContentData; | ||
use Ibexa\Personalization\QueryType\ContentQueryType; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class ContentController extends RestController | ||
{ | ||
/** @var \EzSystems\EzRecommendationClient\Authentication\AuthenticatorInterface */ | ||
private $authenticator; | ||
|
||
/** @var \Ibexa\Personalization\QueryType\ContentQueryType */ | ||
private $contentQueryType; | ||
|
||
/** @var \EzSystems\EzRecommendationClient\Service\ContentServiceInterface */ | ||
private $contentService; | ||
|
||
/** @var \eZ\Publish\API\Repository\SearchService */ | ||
private $searchService; | ||
|
||
public function __construct( | ||
AuthenticatorInterface $authenticator, | ||
ContentQueryType $contentQueryType, | ||
ContentServiceInterface $contentService, | ||
Repository $repository, | ||
SearchService $searchService | ||
) { | ||
$this->authenticator = $authenticator; | ||
$this->contentQueryType = $contentQueryType; | ||
$this->contentService = $contentService; | ||
$this->repository = $repository; | ||
$this->searchService = $searchService; | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function getContentByIdAction(int $contentId, Request $request): ContentData | ||
{ | ||
if (!$this->authenticator->authenticate()) { | ||
throw new AuthenticationFailedException('Access denied: wrong credentials', Response::HTTP_UNAUTHORIZED); | ||
} | ||
|
||
$requestQuery = $request->query; | ||
$contentItems = $this->getContentItems( | ||
$this->contentQueryType->getQueryByContentId($contentId, (string) $requestQuery->get('lang')) | ||
); | ||
|
||
return $this->getContentData($contentItems); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function getContentByRemoteIdAction(string $remoteId, Request $request): ContentData | ||
{ | ||
if (!$this->authenticator->authenticate()) { | ||
throw new AuthenticationFailedException('Access denied: wrong credentials', Response::HTTP_UNAUTHORIZED); | ||
} | ||
|
||
$requestQuery = $request->query; | ||
$contentItems = $this->getContentItems( | ||
$this->contentQueryType->getQueryByContentRemoteId($remoteId, (string) $requestQuery->get('lang')) | ||
); | ||
|
||
return $this->getContentData($contentItems); | ||
} | ||
|
||
/** | ||
* @return array<\eZ\Publish\API\Repository\Values\Content\Search\SearchHit> | ||
* | ||
* @throws \Exception | ||
*/ | ||
private function getContentItems(Query $query): array | ||
{ | ||
return $this->repository->sudo(function () use ($query) { | ||
return $this->searchService->findContent($query)->searchHits; | ||
}); | ||
} | ||
|
||
/** | ||
* @param array<\eZ\Publish\API\Repository\Values\Content\Search\SearchHit> $contentItems | ||
*/ | ||
private function getContentData(array $contentItems): ContentData | ||
{ | ||
$contentData = $this->contentService->prepareContent( | ||
[$contentItems], | ||
new Content() | ||
); | ||
|
||
return new ContentData($contentData); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
ez_recommendation.content_type.get_content: | ||
path: /ez_recommendation/v1/content/{idList} | ||
ez_recommendation.rest.content.get_by_id: | ||
path: /ez_recommendation/v1/content/id/{contentId} | ||
defaults: | ||
_controller: 'EzSystems\EzRecommendationClientBundle\Controller\ContentController::getContentAction' | ||
_controller: 'EzSystems\EzRecommendationClientBundle\Controller\REST\ContentController::getContentByIdAction' | ||
methods: [GET] | ||
requirements: | ||
contentId: '\d+' | ||
|
||
ez_recommendation.rest.content.get_by_remote_id: | ||
path: /ez_recommendation/v1/content/remote-id/{remoteId} | ||
defaults: | ||
_controller: 'EzSystems\EzRecommendationClientBundle\Controller\REST\ContentController::getContentByRemoteIdAction' | ||
requirements: | ||
remoteId: '[a-zA-Z0-9\_\-\/]+' | ||
methods: [GET] | ||
|
||
ez_recommendation.export.download: | ||
path: /ez_recommendation/v1/exportDownload/{filePath} | ||
ez_recommendation.rest.export.download: | ||
path: /ez_recommendation/v1/export/download/{filePath} | ||
defaults: | ||
_controller: 'EzSystems\EzRecommendationClientBundle\Controller\ExportController::downloadAction' | ||
_controller: 'EzSystems\EzRecommendationClientBundle\Controller\REST\ExportController::downloadAction' | ||
requirements: | ||
filePath: '[a-zA-Z0-9\_\-\/]+' |
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
Oops, something went wrong.