Loading app/src/News/Controller/NewsController.php +20 −30 Original line number Diff line number Diff line Loading @@ -2,58 +2,48 @@ namespace App\News\Controller; use App\News\Service\NewsPrepareResponseService; use App\Shared\Abstraction\AbstractController; use App\Shared\DtoFactory\ErrorDtoFactory; use App\News\Request\NewsDetailRequest; use App\News\Request\NewsListingRequest; use App\News\UseCase\NewsGetDetailMainUseCase; use App\News\UseCase\NewsGetDetailUseCase; use App\News\UseCase\NewsGetListingUseUseCase; use App\News\UseCase\NewsGetMainUseCase; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Routing\Attribute\Route; #[Route('/api/v1/news')] class NewsController extends AbstractController { public function __construct( ErrorDtoFactory $errorFactory, private readonly NewsPrepareResponseService $responsePrepareService, private readonly NewsGetListingUseUseCase $getListingUseCase, private readonly NewsGetDetailUseCase $getDetailNews, private readonly NewsGetMainUseCase $getMainNews, private readonly NewsGetDetailMainUseCase $getDetailMainNews, ) { 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, ); public function news(NewsListingRequest $request): JsonResponse { return $this->getListingUseCase->execute($request); } #[Route('/mainNews', name: 'mainNews', methods: ['GET'])] public function mainNews(): JsonResponse { return new JsonResponse($this->responsePrepareService->bornMainNews()); return $this->getMainNews->execute(); } #[Route('/search', name: 'searchNews', methods: ['GET'])] public function search(): JsonResponse public function detailMainNews(): JsonResponse { return new JsonResponse( $this->responsePrepareService->bornDetailMainNews() ); return $this->getDetailMainNews->execute(); } #[Route('/{detailId}', name: 'oneNews', methods: ['GET'])] public function oneNews( #[MapQueryParameter] string $detailId = null ): JsonResponse { return $this->handleDetailElement( $this->responsePrepareService, $detailId, ); public function oneNews(NewsDetailRequest $request): JsonResponse { return $this->getDetailNews->execute($request); } } app/src/News/Dto/NewsDetailElementDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,10 +2,9 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractDetailElement; use App\Shared\Dto\FileDto; class NewsDetailElementDto extends AbstractDetailElement class NewsDetailElementDto { /** * @param string $id Loading app/src/News/Dto/NewsListDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,11 +2,10 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractListDto; use App\Shared\Collection\ListingCollection; use App\Shared\Dto\PaginationDto; class NewsListDto extends AbstractListDto class NewsListDto { /** * @param PaginationDto $pagination Loading app/src/News/Dto/NewsListingElementDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,10 +2,9 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractListingElementDto; use App\Shared\Dto\FileDto; class NewsListingElementDto extends AbstractListingElementDto class NewsListingElementDto { /** * @param string $id Loading app/src/News/Request/NewsDetailRequest.php 0 → 100644 +43 −0 Original line number Diff line number Diff line <?php namespace App\News\Request; use App\Shared\Error\NotFoundError; use App\Shared\Service\ValidationService; use Symfony\Component\HttpFoundation\Request; class NewsDetailRequest { public string $detailId; public function __construct( private readonly ValidationService $validation, ) { $this->populate(); $this->checkAndCorrectParams(); } private function checkAndCorrectParams(): void { if (!$this->validation->isUuidValid($this->detailId)) { throw new NotFoundError('News not found'); } } private function populate(): void { $requestUrl = $this->getRequest()->getUri(); $index = strrpos($requestUrl, "/") + 1; $restaurantId = substr($requestUrl, $index); if (property_exists($this, "detailId")) { $this->{"detailId"} = $restaurantId; } } public function getRequest(): Request { return Request::createFromGlobals(); } } No newline at end of file Loading
app/src/News/Controller/NewsController.php +20 −30 Original line number Diff line number Diff line Loading @@ -2,58 +2,48 @@ namespace App\News\Controller; use App\News\Service\NewsPrepareResponseService; use App\Shared\Abstraction\AbstractController; use App\Shared\DtoFactory\ErrorDtoFactory; use App\News\Request\NewsDetailRequest; use App\News\Request\NewsListingRequest; use App\News\UseCase\NewsGetDetailMainUseCase; use App\News\UseCase\NewsGetDetailUseCase; use App\News\UseCase\NewsGetListingUseUseCase; use App\News\UseCase\NewsGetMainUseCase; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Routing\Attribute\Route; #[Route('/api/v1/news')] class NewsController extends AbstractController { public function __construct( ErrorDtoFactory $errorFactory, private readonly NewsPrepareResponseService $responsePrepareService, private readonly NewsGetListingUseUseCase $getListingUseCase, private readonly NewsGetDetailUseCase $getDetailNews, private readonly NewsGetMainUseCase $getMainNews, private readonly NewsGetDetailMainUseCase $getDetailMainNews, ) { 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, ); public function news(NewsListingRequest $request): JsonResponse { return $this->getListingUseCase->execute($request); } #[Route('/mainNews', name: 'mainNews', methods: ['GET'])] public function mainNews(): JsonResponse { return new JsonResponse($this->responsePrepareService->bornMainNews()); return $this->getMainNews->execute(); } #[Route('/search', name: 'searchNews', methods: ['GET'])] public function search(): JsonResponse public function detailMainNews(): JsonResponse { return new JsonResponse( $this->responsePrepareService->bornDetailMainNews() ); return $this->getDetailMainNews->execute(); } #[Route('/{detailId}', name: 'oneNews', methods: ['GET'])] public function oneNews( #[MapQueryParameter] string $detailId = null ): JsonResponse { return $this->handleDetailElement( $this->responsePrepareService, $detailId, ); public function oneNews(NewsDetailRequest $request): JsonResponse { return $this->getDetailNews->execute($request); } }
app/src/News/Dto/NewsDetailElementDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,10 +2,9 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractDetailElement; use App\Shared\Dto\FileDto; class NewsDetailElementDto extends AbstractDetailElement class NewsDetailElementDto { /** * @param string $id Loading
app/src/News/Dto/NewsListDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,11 +2,10 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractListDto; use App\Shared\Collection\ListingCollection; use App\Shared\Dto\PaginationDto; class NewsListDto extends AbstractListDto class NewsListDto { /** * @param PaginationDto $pagination Loading
app/src/News/Dto/NewsListingElementDto.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,10 +2,9 @@ namespace App\News\Dto; use App\Shared\Abstraction\AbstractListingElementDto; use App\Shared\Dto\FileDto; class NewsListingElementDto extends AbstractListingElementDto class NewsListingElementDto { /** * @param string $id Loading
app/src/News/Request/NewsDetailRequest.php 0 → 100644 +43 −0 Original line number Diff line number Diff line <?php namespace App\News\Request; use App\Shared\Error\NotFoundError; use App\Shared\Service\ValidationService; use Symfony\Component\HttpFoundation\Request; class NewsDetailRequest { public string $detailId; public function __construct( private readonly ValidationService $validation, ) { $this->populate(); $this->checkAndCorrectParams(); } private function checkAndCorrectParams(): void { if (!$this->validation->isUuidValid($this->detailId)) { throw new NotFoundError('News not found'); } } private function populate(): void { $requestUrl = $this->getRequest()->getUri(); $index = strrpos($requestUrl, "/") + 1; $restaurantId = substr($requestUrl, $index); if (property_exists($this, "detailId")) { $this->{"detailId"} = $restaurantId; } } public function getRequest(): Request { return Request::createFromGlobals(); } } No newline at end of file