Loading app/config/services.yaml +6 −8 Original line number Diff line number Diff line Loading @@ -14,11 +14,9 @@ services: # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones App\Restaurants\: resource: '../src/Restaurants/' App\News\: resource: '../src/News/' App\Shared\: resource: '../src/Shared/' No newline at end of file App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' app/src/News/Collection/NewsCategoryCollection.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php namespace App\News\Collection; use App\News\Dto\NewsCategoryDto; use App\Shared\Collection\DtoCollection; class NewsCategoryCollection extends DtoCollection { private string $collectionType = NewsCategoryDto::class; public function __construct(array $data = []) { parent::__construct($this->collectionType, $data); } } app/src/News/Controller/NewsController.php +27 −22 Original line number Diff line number Diff line Loading @@ -2,16 +2,11 @@ namespace App\News\Controller; use App\News\Request\NewsListingRequest; use App\News\Service\NewsDetailService; use App\News\Service\NewsListingService; use App\News\Service\NewsMainNewsService; use App\News\Service\NewsSearchService; use App\News\Service\NewsPrepareResponseService; use App\Shared\Abstraction\AbstractController; use App\Shared\DtoFactory\ErrorDtoFactory; use App\Shared\Request\DetailRequest; use App\Shared\Request\EmptyRequest; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Routing\Attribute\Route; #[Route('/api/v1/news')] Loading @@ -19,36 +14,46 @@ class NewsController extends AbstractController { public function __construct( ErrorDtoFactory $errorFactory, private readonly NewsDetailService $detailService, private readonly NewsListingService $listingService, private readonly NewsMainNewsService $mainNewsService, private readonly NewsSearchService $searchService, private readonly NewsPrepareResponseService $responsePrepareService, ) { parent::__construct($errorFactory); } #[Route('/', name: 'news', methods: ['GET'])] public function news(NewsListingRequest $request): JsonResponse { return $this->handle($this->listingService, $request); 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'])] public function mainNews(EmptyRequest $request): JsonResponse public function mainNews(): JsonResponse { return $this->handle($this->mainNewsService, $request); return new JsonResponse($this->responsePrepareService->bornMainNews()); } #[Route('/search', name: 'searchNews', methods: ['GET'])] public function search(EmptyRequest $request): JsonResponse public function search(): JsonResponse { return $this->handle($this->searchService, $request); return new JsonResponse( $this->responsePrepareService->bornDetailMainNews() ); } #[Route('/{detailId}', name: 'oneNews', methods: ['GET'])] public function oneNews(DetailRequest $request): JsonResponse { return $this->handle($this->detailService, $request); public function oneNews( #[MapQueryParameter] string $detailId = null ): JsonResponse { return $this->handleDetailElement( $this->responsePrepareService, $detailId, ); } } app/src/News/Dto/NewsCategoryDto.php +3 −6 Original line number Diff line number Diff line Loading @@ -2,15 +2,12 @@ namespace App\News\Dto; use App\Shared\Abstraction\DtoInterface; class NewsCategoryDto implements DtoInterface class NewsCategoryDto { public function __construct( public string $id, public string $name, public string $code, ) {} ) { } } app/src/News/Dto/NewsDetailElementDto.php +12 −9 Original line number Diff line number Diff line Loading @@ -2,23 +2,26 @@ namespace App\News\Dto; use App\Shared\Abstraction\DtoInterface; use App\Shared\Abstraction\AbstractDetailElement; use App\Shared\Dto\FileDto; class NewsDetailElementDto implements DtoInterface class NewsDetailElementDto extends AbstractDetailElement { /** * @param string $id * @param string $name * @param string $description * @param string $createAt * @param string|null $text * @param FileDto|null $image Преаью */ public function __construct( public string $id, public string $name, public string $description, public string $createAt, public ?string $text = null, /** @var FileDto Преаью */ public ?FileDto $image = null, ) {} ) { } } Loading
app/config/services.yaml +6 −8 Original line number Diff line number Diff line Loading @@ -14,11 +14,9 @@ services: # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones App\Restaurants\: resource: '../src/Restaurants/' App\News\: resource: '../src/News/' App\Shared\: resource: '../src/Shared/' No newline at end of file App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php'
app/src/News/Collection/NewsCategoryCollection.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php namespace App\News\Collection; use App\News\Dto\NewsCategoryDto; use App\Shared\Collection\DtoCollection; class NewsCategoryCollection extends DtoCollection { private string $collectionType = NewsCategoryDto::class; public function __construct(array $data = []) { parent::__construct($this->collectionType, $data); } }
app/src/News/Controller/NewsController.php +27 −22 Original line number Diff line number Diff line Loading @@ -2,16 +2,11 @@ namespace App\News\Controller; use App\News\Request\NewsListingRequest; use App\News\Service\NewsDetailService; use App\News\Service\NewsListingService; use App\News\Service\NewsMainNewsService; use App\News\Service\NewsSearchService; use App\News\Service\NewsPrepareResponseService; use App\Shared\Abstraction\AbstractController; use App\Shared\DtoFactory\ErrorDtoFactory; use App\Shared\Request\DetailRequest; use App\Shared\Request\EmptyRequest; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Routing\Attribute\Route; #[Route('/api/v1/news')] Loading @@ -19,36 +14,46 @@ class NewsController extends AbstractController { public function __construct( ErrorDtoFactory $errorFactory, private readonly NewsDetailService $detailService, private readonly NewsListingService $listingService, private readonly NewsMainNewsService $mainNewsService, private readonly NewsSearchService $searchService, private readonly NewsPrepareResponseService $responsePrepareService, ) { parent::__construct($errorFactory); } #[Route('/', name: 'news', methods: ['GET'])] public function news(NewsListingRequest $request): JsonResponse { return $this->handle($this->listingService, $request); 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'])] public function mainNews(EmptyRequest $request): JsonResponse public function mainNews(): JsonResponse { return $this->handle($this->mainNewsService, $request); return new JsonResponse($this->responsePrepareService->bornMainNews()); } #[Route('/search', name: 'searchNews', methods: ['GET'])] public function search(EmptyRequest $request): JsonResponse public function search(): JsonResponse { return $this->handle($this->searchService, $request); return new JsonResponse( $this->responsePrepareService->bornDetailMainNews() ); } #[Route('/{detailId}', name: 'oneNews', methods: ['GET'])] public function oneNews(DetailRequest $request): JsonResponse { return $this->handle($this->detailService, $request); public function oneNews( #[MapQueryParameter] string $detailId = null ): JsonResponse { return $this->handleDetailElement( $this->responsePrepareService, $detailId, ); } }
app/src/News/Dto/NewsCategoryDto.php +3 −6 Original line number Diff line number Diff line Loading @@ -2,15 +2,12 @@ namespace App\News\Dto; use App\Shared\Abstraction\DtoInterface; class NewsCategoryDto implements DtoInterface class NewsCategoryDto { public function __construct( public string $id, public string $name, public string $code, ) {} ) { } }
app/src/News/Dto/NewsDetailElementDto.php +12 −9 Original line number Diff line number Diff line Loading @@ -2,23 +2,26 @@ namespace App\News\Dto; use App\Shared\Abstraction\DtoInterface; use App\Shared\Abstraction\AbstractDetailElement; use App\Shared\Dto\FileDto; class NewsDetailElementDto implements DtoInterface class NewsDetailElementDto extends AbstractDetailElement { /** * @param string $id * @param string $name * @param string $description * @param string $createAt * @param string|null $text * @param FileDto|null $image Преаью */ public function __construct( public string $id, public string $name, public string $description, public string $createAt, public ?string $text = null, /** @var FileDto Преаью */ public ?FileDto $image = null, ) {} ) { } }