Newer
Older
Александр Плохих
committed
<?php
use App\Shared\Abstraction\AbstractController;
use App\Shared\DtoFactory\ErrorDtoFactory;
Александр Плохих
committed
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
Александр Плохих
committed
use Symfony\Component\Routing\Attribute\Route;
class NewsController extends AbstractController
Александр Плохих
committed
{
public function __construct(
private readonly NewsPrepareResponseService $responsePrepareService,
) {
parent::__construct($errorFactory);
}
#[Route('/', name: 'news', methods: ['GET'])]
public function news(
#[MapQueryParameter] int $page = 1,
#[MapQueryParameter] int $limit = 12,
#[MapQueryParameter] string $news_category = null
): JsonResponse {
return $this->handleListing(
$this->responsePrepareService,
$page,
$limit,
$news_category,
);
}
#[Route('/mainNews', name: 'mainNews', methods: ['GET'])]
return new JsonResponse($this->responsePrepareService->bornMainNews());
}
#[Route('/search', name: 'searchNews', methods: ['GET'])]
Александр Плохих
committed
{
return new JsonResponse(
$this->responsePrepareService->bornDetailMainNews()
);
Александр Плохих
committed
}
#[Route('/{detailId}', name: 'oneNews', methods: ['GET'])]
public function oneNews(
#[MapQueryParameter] string $detailId = null
): JsonResponse {
return $this->handleDetailElement(
$this->responsePrepareService,
$detailId,
);