<?php declare(strict_types=1);
namespace Dvdw\Events\Content\DvdwEvent\SalesChannel;
use Dvdw\Cache\Framework\Adapter\Cache\CacheHelper;
use Dvdw\Cache\Framework\Adapter\Cache\CacheItemInfo;
use OpenApi\Annotations as OA;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
class CachedDvdwEventRoute extends AbstractDvdwEventRoute
{
public CONST ALL_TAG = 'dvdw-event-route';
private AbstractDvdwEventRoute $decorated;
private CacheHelper $cacheHelper;
public function __construct(
AbstractDvdwEventRoute $decorated,
CacheHelper $cacheHelper
)
{
$this->decorated = $decorated;
$this->cacheHelper = $cacheHelper;
}
public static function buildName(string $id): string
{
return 'dvdw-event-route-' . $id;
}
public function getDecorated(): AbstractDvdwEventRoute
{
return $this->decorated;
}
/**
* @OA\Post(
* path="/dvdw-event",
* summary="Fetch dvdw events",
* description="Fetch the events according to criteria.",
* operationId="readDvdwEvents",
* tags={"Store API", "System & Context"},
* @OA\Response(
* response="200",
* description="Returns a collection of events that fit the criteria.",
* @OA\JsonContent(
* type="object",
* allOf={
* @OA\Schema(ref="#/components/schemas/EntitySearchResult"),
* @OA\Schema(type="object",
* @OA\Property(
* type="array",
* property="elements",
* @OA\Items(ref="#/components/schemas/DvdwEvent")
* )
* )
* }
* )
* )
* )
* @Entity("dvdw_event")
* @Route(path="/store-api/dvdw-event", name="store-api.dvdw-event", methods={"GET", "POST"})
*/
public function load(Request $request, Criteria $criteria, SalesChannelContext $context): DvdwEventResponse
{
/** @var DvdwEventResponse $response */
$response = $this->cacheHelper->get(
new CacheItemInfo(
$this,
self::ALL_TAG,
$request,
$criteria,
$context,
$this->getDecorated()
)
);
return $response;
}
}