diff --git a/app/src/News/Controller/NewsController.php b/app/src/News/Controller/NewsController.php index 98694b5ec4a9192718596646c7ec85e8e30bf140..34e1dbba36c09283223134479ddea3d751b61ee3 100644 --- a/app/src/News/Controller/NewsController.php +++ b/app/src/News/Controller/NewsController.php @@ -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); } } diff --git a/app/src/News/Dto/NewsDetailElementDto.php b/app/src/News/Dto/NewsDetailElementDto.php index 530f5e0fff1abcf85a00f85f4c8dbf8b7f34be78..e715ddaffc810c8eb9b4cd28874d45b432829164 100644 --- a/app/src/News/Dto/NewsDetailElementDto.php +++ b/app/src/News/Dto/NewsDetailElementDto.php @@ -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 diff --git a/app/src/News/Dto/NewsListDto.php b/app/src/News/Dto/NewsListDto.php index 63da8fa0380affa7a430ff02155aa7cbe3f01f58..833a93c6a3a508198c9f303d2bab3e082232c2c9 100644 --- a/app/src/News/Dto/NewsListDto.php +++ b/app/src/News/Dto/NewsListDto.php @@ -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 diff --git a/app/src/News/Dto/NewsListingElementDto.php b/app/src/News/Dto/NewsListingElementDto.php index a291ea14386660ad5a3fde4565ccd0179906b4ea..0ff49bb2987eadaaa721f80c34184c73fbfb3e64 100644 --- a/app/src/News/Dto/NewsListingElementDto.php +++ b/app/src/News/Dto/NewsListingElementDto.php @@ -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 diff --git a/app/src/News/Request/NewsDetailRequest.php b/app/src/News/Request/NewsDetailRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..8fdcf654405a1161f58e4cee8bb4ead33de4dc28 --- /dev/null +++ b/app/src/News/Request/NewsDetailRequest.php @@ -0,0 +1,43 @@ +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 diff --git a/app/src/News/Request/NewsListingRequest.php b/app/src/News/Request/NewsListingRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..fc803834be8229fb702bf31256b4b8206ada0831 --- /dev/null +++ b/app/src/News/Request/NewsListingRequest.php @@ -0,0 +1,51 @@ +populate(); + $this->checkAndCorrectParams(); + } + + private function checkAndCorrectParams(): void + { + if (!$this->validation->isPageValid($this->page)) { + $this->page = 1; + } + + if (!$this->validation->isLimitValid($this->limit)) { + $this->limit = 12; + } + + if (!$this->validation->isUuidValid($this->news_category)) { + $this->news_category = null; + } + } + + private function populate(): void + { + foreach ( + $this->getRequest()->query->getIterator() as $property => $value + ) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } + } + + public function getRequest(): Request + { + return Request::createFromGlobals(); + } +} \ No newline at end of file diff --git a/app/src/News/Service/NewsPrepareResponseService.php b/app/src/News/Service/NewsPrepareResponseService.php index dbdd17c0c067ce8ef79a43c6635b1c801dc29f92..b652b1d9970390c8dfa24409f88614501e67703b 100644 --- a/app/src/News/Service/NewsPrepareResponseService.php +++ b/app/src/News/Service/NewsPrepareResponseService.php @@ -3,61 +3,43 @@ namespace App\News\Service; use App\News\Dto\NewsDetailElementDto; +use App\News\Dto\NewsListDto; use App\News\Dto\NewsListingElementDto; use App\News\DtoFactory\NewsCategoryDtoFactory; use App\News\DtoFactory\NewsDetailElementDtoFactory; use App\News\DtoFactory\NewsFilterVariantsDtoFactory; use App\News\DtoFactory\NewsListDtoFactory; use App\News\DtoFactory\NewsListingElementDtoFactory; -use App\Shared\Abstraction\AbstractListDto; -use App\Shared\Abstraction\ServiceInterface; +use App\News\Request\NewsDetailRequest; +use App\News\Request\NewsListingRequest; use App\Shared\DtoFactory\PaginationDtoFactory; -use App\Shared\Error\NonValidUuidError; use App\Shared\Error\NotFoundError; use App\Shared\Repository\NewsCategoriesRepository; use App\Shared\Repository\NewsRepository; -use App\Shared\Service\ValidateService; -readonly class NewsPrepareResponseService implements ServiceInterface +class NewsPrepareResponseService { public function __construct( - private NewsRepository $news, - private NewsCategoriesRepository $newsCategories, - private PaginationDtoFactory $paginationFactory, - private NewsListingElementDtoFactory $listFactory, - private NewsFilterVariantsDtoFactory $filterFactory, - private NewsListDtoFactory $listingFactory, - private NewsCategoryDtoFactory $categoryFactory, - private ValidateService $validate, - private NewsDetailElementDtoFactory $detailElementFactory + private readonly NewsRepository $news, + private readonly NewsCategoriesRepository $newsCategories, + private readonly PaginationDtoFactory $paginationFactory, + private readonly NewsListingElementDtoFactory $listFactory, + private readonly NewsFilterVariantsDtoFactory $filterFactory, + private readonly NewsListDtoFactory $listingFactory, + private readonly NewsCategoryDtoFactory $categoryFactory, + private readonly NewsDetailElementDtoFactory $detailElementFactory ) { } - /** - * @param int $page - * @param int $limit - * @param array|null ...$filters - * @return AbstractListDto - */ - public function bornListDto( - int $page, - int $limit, - ?array $filters - ): AbstractListDto { - $filters['news_category'] = $filters[0]; - if (!$this->validate->isValidUuid($filters['news_category'])) { - $filters['news_category'] = null; - } - - $this->validate->correctPagination($page, $limit); - + public function bornListDto(NewsListingRequest $request): NewsListDto + { $countOfNews = $this->news->getCountWithFilters( - $filters['news_category'] + $request->news_category ); $pagination = $this->paginationFactory->create( - $page, - $limit, + $request->page, + $request->limit, $countOfNews ); @@ -68,8 +50,8 @@ readonly class NewsPrepareResponseService implements ServiceInterface $list = $this->listFactory->createCollection( $this->news->getWithFilters( - $filters['news_category'], - $limit, + $request->news_category, + $request->limit, $offset ) ); @@ -97,13 +79,9 @@ readonly class NewsPrepareResponseService implements ServiceInterface return $this->detailElementFactory->create($this->news->getMainNews()); } - public function bornDetailElement(string $detailId): NewsDetailElementDto - { - if (!$this->validate->isValidUuid($detailId)) { - throw new NonValidUuidError(); - } - - $news = $this->news->find($detailId); + public function bornDetailElement(NewsDetailRequest $request + ): NewsDetailElementDto { + $news = $this->news->find($request->detailId); if ($news === null) { throw new NotFoundError('News not found'); diff --git a/app/src/News/UseCase/NewsGetDetailMainUseCase.php b/app/src/News/UseCase/NewsGetDetailMainUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..92725a121c29184bc53d4071b17c548a4e1ec7c4 --- /dev/null +++ b/app/src/News/UseCase/NewsGetDetailMainUseCase.php @@ -0,0 +1,27 @@ +prepareRequestService->bornDetailMainNews() + ); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/src/News/UseCase/NewsGetDetailUseCase.php b/app/src/News/UseCase/NewsGetDetailUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..2605bd94f84d89844e02a0089589e2190969bca5 --- /dev/null +++ b/app/src/News/UseCase/NewsGetDetailUseCase.php @@ -0,0 +1,34 @@ +responsePrepareService->bornDetailElement($request) + ); + } catch (NotFoundError $error) { + $errorDto = $this->errorFactory->create($error); + return new JsonResponse($errorDto, $errorDto->status); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/src/News/UseCase/NewsGetListingUseUseCase.php b/app/src/News/UseCase/NewsGetListingUseUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..736c1f97850033d4e8cafb8aba35febc9e85bc46 --- /dev/null +++ b/app/src/News/UseCase/NewsGetListingUseUseCase.php @@ -0,0 +1,27 @@ +prepareRequestService->bornListDto($request) + ); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} diff --git a/app/src/News/UseCase/NewsGetMainUseCase.php b/app/src/News/UseCase/NewsGetMainUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..9516d1899e9abfc08a4045dcb1ccae54037d0fe2 --- /dev/null +++ b/app/src/News/UseCase/NewsGetMainUseCase.php @@ -0,0 +1,26 @@ +responsePrepareService->bornMainNews() + ); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/src/Restaurants/Controller/RestaurantsController.php b/app/src/Restaurants/Controller/RestaurantsController.php index eea4f2d328229d669f683862b45e87e582b78f7e..c589e3acfaba4a340b59a12ea0df51bafde7d192 100644 --- a/app/src/Restaurants/Controller/RestaurantsController.php +++ b/app/src/Restaurants/Controller/RestaurantsController.php @@ -2,45 +2,32 @@ namespace App\Restaurants\Controller; -use App\Restaurants\Service\RestaurantPrepareRequestService; -use App\Shared\Abstraction\AbstractController; -use App\Shared\DtoFactory\ErrorDtoFactory; +use App\Restaurants\UseCase\RestaurantGetListingUseCase; +use App\Restaurants\Request\RestaurantDetailRequest; +use App\Restaurants\Request\RestaurantListingRequest; +use App\Restaurants\UseCase\RestaurantGetDetailUseCase; +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/restaurants')] class RestaurantsController extends AbstractController { public function __construct( - ErrorDtoFactory $errorFactory, - private readonly RestaurantPrepareRequestService $responsePrepareService, + private readonly RestaurantGetListingUseCase $getListingUseCase, + private readonly RestaurantGetDetailUseCase $getDetailUseCase, ) { - parent::__construct($errorFactory); } #[Route('/', name: 'restaurants', methods: ['GET'])] - public function restaurants( - #[MapQueryParameter] int $page = 1, - #[MapQueryParameter] int $limit = 12, - #[MapQueryParameter] string $restaurant_type_id = null, - #[MapQueryParameter] string $kitchen_id = null, - ): JsonResponse { - return $this->handleListing( - $this->responsePrepareService, - $page, - $limit, - $restaurant_type_id, - $kitchen_id, - ); + public function restaurants(RestaurantListingRequest $request): JsonResponse + { + return $this->getListingUseCase->execute($request); } #[Route('/{detailId}', name: 'restaurant', methods: ['GET'])] - public function restaurant(#[MapQueryParameter] string $detailId = null - ): JsonResponse { - return $this->handleDetailElement( - $this->responsePrepareService, - $detailId, - ); + public function restaurant(RestaurantDetailRequest $request): JsonResponse + { + return $this->getDetailUseCase->execute($request); } } diff --git a/app/src/Restaurants/Dto/RestaurantDetailElementDto.php b/app/src/Restaurants/Dto/RestaurantDetailElementDto.php index bf4d83f56f3e0cd59dd83c78f5484bc8d9263fe3..75eaa59b8ee8d2a4851bea1f10fd2e77dde0d383 100644 --- a/app/src/Restaurants/Dto/RestaurantDetailElementDto.php +++ b/app/src/Restaurants/Dto/RestaurantDetailElementDto.php @@ -4,12 +4,11 @@ namespace App\Restaurants\Dto; use App\Restaurants\Collection\KitchenCollection; use App\Restaurants\Collection\TagCollection; -use App\Shared\Abstraction\AbstractDetailElement; use App\Shared\Collection\FileCollection; use App\Shared\Collection\StringCollection; use App\Shared\Dto\FileDto; -class RestaurantDetailElementDto extends AbstractDetailElement +class RestaurantDetailElementDto { /** * @param string $id diff --git a/app/src/Restaurants/Dto/RestaurantListDto.php b/app/src/Restaurants/Dto/RestaurantListDto.php index 79354d8e3871b17de6a5b1bd4532c02384fdb22c..1e6ac5d5b995500610ab768c88fab3344a3d4e0e 100644 --- a/app/src/Restaurants/Dto/RestaurantListDto.php +++ b/app/src/Restaurants/Dto/RestaurantListDto.php @@ -2,11 +2,10 @@ namespace App\Restaurants\Dto; -use App\Shared\Abstraction\AbstractListDto; use App\Shared\Collection\ListingCollection; use App\Shared\Dto\PaginationDto; -class RestaurantListDto extends AbstractListDto +class RestaurantListDto { /** * @param PaginationDto $pagination diff --git a/app/src/Restaurants/Dto/RestaurantListingElementDto.php b/app/src/Restaurants/Dto/RestaurantListingElementDto.php index 4d7f3dc09b3b390fd00a8b2f0bf37d6c4d9da0ee..2ffed4543b1f377faad9253c32bd6f9b1590fdde 100644 --- a/app/src/Restaurants/Dto/RestaurantListingElementDto.php +++ b/app/src/Restaurants/Dto/RestaurantListingElementDto.php @@ -2,10 +2,9 @@ namespace App\Restaurants\Dto; -use App\Shared\Abstraction\AbstractListingElementDto; use App\Shared\Dto\FileDto; -class RestaurantListingElementDto extends AbstractListingElementDto +class RestaurantListingElementDto { public function __construct( public string $id, diff --git a/app/src/Restaurants/Request/RestaurantDetailRequest.php b/app/src/Restaurants/Request/RestaurantDetailRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..fbc0acb5cea941c6acfe474f32086d071df1cb7d --- /dev/null +++ b/app/src/Restaurants/Request/RestaurantDetailRequest.php @@ -0,0 +1,43 @@ +populate(); + $this->checkAndCorrectParams(); + } + + private function checkAndCorrectParams(): void + { + if (!$this->validation->isUuidValid($this->detailId)) { + throw new NotFoundError('Restaurant 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(); + } +} diff --git a/app/src/Restaurants/Request/RestaurantListingRequest.php b/app/src/Restaurants/Request/RestaurantListingRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..a198fa061beefadc64053ac68fd0998643759a18 --- /dev/null +++ b/app/src/Restaurants/Request/RestaurantListingRequest.php @@ -0,0 +1,56 @@ +populate(); + $this->checkAndCorrectParams(); + } + + private function checkAndCorrectParams(): void + { + if (!$this->validation->isPageValid($this->page)) { + $this->page = 1; + } + + if (!$this->validation->isLimitValid($this->limit)) { + $this->limit = 12; + } + + if (!$this->validation->isUuidValid($this->restaurant_type_id)) { + $this->restaurant_type_id = null; + } + + if (!$this->validation->isUuidValid($this->kitchen_id)) { + $this->kitchen_id = null; + } + } + + private function populate(): void + { + foreach ( + $this->getRequest()->query->getIterator() as $property => $value + ) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } + } + + public function getRequest(): Request + { + return Request::createFromGlobals(); + } +} \ No newline at end of file diff --git a/app/src/Restaurants/Service/RestaurantPrepareRequestService.php b/app/src/Restaurants/Service/RestaurantPrepareRequestService.php index 742d4c4af306f26016f8432008eb5b7367c71633..9d24a6ad4f53a6050e64f8f80f28dd49c0197b98 100644 --- a/app/src/Restaurants/Service/RestaurantPrepareRequestService.php +++ b/app/src/Restaurants/Service/RestaurantPrepareRequestService.php @@ -2,25 +2,24 @@ namespace App\Restaurants\Service; +use App\Restaurants\Dto\RestaurantDetailElementDto; +use App\Restaurants\Dto\RestaurantListDto; use App\Restaurants\DtoFactory\KitchenTypeDtoFactory; use App\Restaurants\DtoFactory\RestaurantDetailElementDtoFactory; use App\Restaurants\DtoFactory\RestaurantFilterVariantsDtoFactory; use App\Restaurants\DtoFactory\RestaurantListDtoFactory; use App\Restaurants\DtoFactory\RestaurantListingElementDtoFactory; use App\Restaurants\DtoFactory\RestaurantTypeDtoFactory; -use App\Shared\Abstraction\AbstractDetailElement; -use App\Shared\Abstraction\AbstractListDto; -use App\Shared\Abstraction\ServiceInterface; +use App\Restaurants\Request\RestaurantDetailRequest; +use App\Restaurants\Request\RestaurantListingRequest; use App\Shared\DtoFactory\PaginationDtoFactory; -use App\Shared\Error\NonValidUuidError; use App\Shared\Error\NotFoundError; use App\Shared\Repository\KitchensRepository; use App\Shared\Repository\RestaurantsRepository; use App\Shared\Repository\RestaurantTypesRepository; -use App\Shared\Service\ValidateService; use JsonException; -class RestaurantPrepareRequestService implements ServiceInterface +class RestaurantPrepareRequestService { public function __construct( private readonly RestaurantsRepository $restaurants, @@ -33,41 +32,24 @@ class RestaurantPrepareRequestService implements ServiceInterface private readonly KitchenTypeDtoFactory $kitchenFactory, private readonly RestaurantListDtoFactory $listingFactory, private readonly RestaurantDetailElementDtoFactory $detailFactory, - private readonly ValidateService $validate, ) { } /** - * @param int $page - * @param int $limit - * @param array|null $filters - * @return AbstractListDto + * @param RestaurantListingRequest $request + * @return RestaurantListDto */ - public function bornListDto( - int $page, - int $limit, - ?array $filters - ): AbstractListDto { - $filters['restaurant_type_id'] = $filters[0]; - $filters['kitchen_id'] = $filters[1]; - if (!$this->validate->isValidUuid($filters['restaurant_type_id'])) { - $filters['news_category'] = null; - } - if (!$this->validate->isValidUuid($filters['kitchen_id'])) { - $filters['news_category'] = null; - } - $this->validate->correctPagination($page, $limit); - + public function bornListDto(RestaurantListingRequest $request): RestaurantListDto { $countOfRestaurants = $this ->restaurants ->getCountWithFilters( - $filters['restaurant_type_id'], - $filters['kitchen_id'] + $request->restaurant_type_id, + $request->kitchen_id, ); $pagination = $this->paginationFactory->create( - $page, - $limit, + $request->page, + $request->limit, $countOfRestaurants, ); @@ -78,8 +60,8 @@ class RestaurantPrepareRequestService implements ServiceInterface $list = $this->listFactory->createCollection( $this->restaurants->getWithFilters( - $filters['kitchen_id'], - $filters['restaurant_type_id'], + $request->kitchen_id, + $request->restaurant_type_id, $pagination->pageSize, $offset, ), @@ -99,19 +81,13 @@ class RestaurantPrepareRequestService implements ServiceInterface } /** - * @param string $detailId - * @return AbstractDetailElement + * @param RestaurantDetailRequest $request + * @return RestaurantDetailElementDto * @throws JsonException */ public - function bornDetailElement( - string $detailId - ): AbstractDetailElement { - if (!$this->validate->isValidUuid($detailId)) { - throw new NonValidUuidError(); - } - - $restaurant = $this->restaurants->find($detailId); + function bornDetailElement(RestaurantDetailRequest $request): RestaurantDetailElementDto { + $restaurant = $this->restaurants->find($request->detailId); if ($restaurant === null) { throw new NotFoundError('Restaurant not found'); diff --git a/app/src/Restaurants/UseCase/RestaurantGetDetailUseCase.php b/app/src/Restaurants/UseCase/RestaurantGetDetailUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..e36941547087cac0b72f8c777f3d35bfce79ebca --- /dev/null +++ b/app/src/Restaurants/UseCase/RestaurantGetDetailUseCase.php @@ -0,0 +1,34 @@ +responsePrepareService->bornDetailElement($request) + ); + } catch (NotFoundError $error) { + $errorDto = $this->errorFactory->create($error); + return new JsonResponse($errorDto, $errorDto->status); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/src/Restaurants/UseCase/RestaurantGetListingUseCase.php b/app/src/Restaurants/UseCase/RestaurantGetListingUseCase.php new file mode 100644 index 0000000000000000000000000000000000000000..2b34a0318b47383f245b3f8d4b7ee87d584dc6fd --- /dev/null +++ b/app/src/Restaurants/UseCase/RestaurantGetListingUseCase.php @@ -0,0 +1,27 @@ +prepareRequestService->bornListDto($request) + ); + } catch (Throwable) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} diff --git a/app/src/Shared/Abstraction/AbstractController.php b/app/src/Shared/Abstraction/AbstractController.php index 884cc922e9baffd23ebf9f18babd4846590d7845..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/app/src/Shared/Abstraction/AbstractController.php +++ b/app/src/Shared/Abstraction/AbstractController.php @@ -1,53 +0,0 @@ -|null $filters - * @return JsonResponse - */ - protected function handleListing( - ServiceInterface $service, - int $page = 1, - int $limit = 12, - ?string ...$filters, - ): JsonResponse { - try { - return new JsonResponse($service->bornListDto($page, $limit, $filters)); - } catch (Throwable) { - return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); - } - } - - protected function handleDetailElement( - ServiceInterface $service, - string $detailId, - ): JsonResponse { -// try { - return new JsonResponse($service->bornDetailElement($detailId)); -// } catch (BaseError $error) { -// $errorDto = $this->errorFactory->create($error); -// -// return new JsonResponse($errorDto, $errorDto->status); -// } catch (Throwable) { -// return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -// } - } -} diff --git a/app/src/Shared/Abstraction/AbstractDetailElement.php b/app/src/Shared/Abstraction/AbstractDetailElement.php deleted file mode 100644 index 6386d81c464baace010d6ccc05cdcb2ee4ed8b6f..0000000000000000000000000000000000000000 --- a/app/src/Shared/Abstraction/AbstractDetailElement.php +++ /dev/null @@ -1,9 +0,0 @@ - */ - public ListingCollection $list; -} diff --git a/app/src/Shared/Abstraction/AbstractListingElementDto.php b/app/src/Shared/Abstraction/AbstractListingElementDto.php deleted file mode 100644 index 9c676fdb59cace93ab5d4ace88d592225e8addf8..0000000000000000000000000000000000000000 --- a/app/src/Shared/Abstraction/AbstractListingElementDto.php +++ /dev/null @@ -1,10 +0,0 @@ -|null $filters - * @return AbstractListDto - */ - public function bornListDto( - int $page, - int $limit, - ?array $filters - ): AbstractListDto; - - public function bornDetailElement(string $detailId): AbstractDetailElement; -} - diff --git a/app/src/Shared/DtoFactory/PaginationDtoFactory.php b/app/src/Shared/DtoFactory/PaginationDtoFactory.php index 7973036fc7b4e5549073c909a417c8ad744fd0e3..f3787bdbf19e38406683ec766d959874759cc9ce 100644 --- a/app/src/Shared/DtoFactory/PaginationDtoFactory.php +++ b/app/src/Shared/DtoFactory/PaginationDtoFactory.php @@ -8,10 +8,9 @@ class PaginationDtoFactory { public function create(int $page, int $limit, int $total): PaginationDto { - $pageSize = $limit > 0 ? $limit : 12; - $pages = ceil($total / $pageSize); + $pages = ceil($total / $limit); $page = ($page > 1) && ($page <= $pages) ? $page : 1; - return new PaginationDto($page, $pages, $pageSize); + return new PaginationDto($page, $pages, $limit); } } diff --git a/app/src/Shared/Service/ValidateService.php b/app/src/Shared/Service/ValidateService.php deleted file mode 100644 index d424d6f1d3f380b2b92a40f4702f7cc47e0c3bbc..0000000000000000000000000000000000000000 --- a/app/src/Shared/Service/ValidateService.php +++ /dev/null @@ -1,25 +0,0 @@ -= 1; + } + + public function isLimitValid(int $limit): bool + { + return $limit >= 1; + } +}