<?php declare(strict_types=1);
namespace NetzpBlog6\Controller\StoreApi\BlogListing;
use NetzpBlog6\Helper\BlogHelper;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use OpenApi\Annotations as OA;
use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Component\Routing\Annotation\Route;
/**
* @RouteScope(scopes={"store-api"})
*/
class BlogListingRoute extends AbstractBlogListingRoute
{
/**
* @var EntityRepositoryInterface
*/
protected $blogRepository;
private $helper;
public function __construct(EntityRepositoryInterface $blogRepository, BlogHelper $helper)
{
$this->blogRepository = $blogRepository;
$this->helper = $helper;
}
public function getDecorated(): AbstractBlogListingRoute
{
throw new DecorationPatternException(self::class);
}
/**
* @Entity("s_plugin_netzp_blog")
* @OA\Post(
* path="/bloglisting",
* summary="This route can be used to load a blog listing",
* operationId="readNetzpBlogListing",
* tags={"Store API", "NetzpBlog"},
* @OA\Parameter(name="Api-Basic-Parameters"),
* @OA\Response(
* response="200",
* description="",
* @OA\JsonContent(type="object",
* @OA\Property(
* property="total",
* type="integer",
* description="Total amount"
* ),
* @OA\Property(
* property="aggregations",
* type="object",
* description="aggregation result"
* )
* )
* )
* )
* @Route("/store-api/bloglisting/{navigationId?}", name="store-api.s_plugin_netzp_blog_listing.load", methods={"GET", "POST"})
*/
public function load($navigationId, Criteria $criteria, SalesChannelContext $salesChannelContext,
?string $categoryId, ?string $authorId, ?array $tags, ?string $sortOrder): BlogListingRouteResponse
{
$posts = $this->helper->getBlogPosts(
$criteria, $salesChannelContext,
$categoryId, $authorId, $tags, $sortOrder);
return new BlogListingRouteResponse($posts);
}
}