Commit 819d40f2 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

STA-966 | Рефакторинг

parent e67782aa
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -20,29 +20,34 @@ class NewsController extends AbstractController
    #[Route('/news', name: 'news', methods: ['GET'])]
    public function news(NewsListRequest $request): Response
    {
        return $this->json($this->newsService->getNewsByRequest($request));
        return $this->json(
            $this->newsService->getNewsByRequest($request)
        );
    }

    #[Route('/news/mainNews', name: 'mainNews', methods: ['GET'])]
    public function mainNews(): Response
    {
        $mainNews = $this->newsService->getMainNews();
        return $this->json($mainNews);
        return $this->json(
            $this->newsService->getMainNews()
        );
    }

    #[Route('/news/search', name: 'newsSearch', methods: ['GET'])]
    public function newsSearch(): Response
    {
        $newsSearch = $this->newsService->getNewsSearch();
        return $this->json($newsSearch);
        return $this->json(
            $this->newsService->getNewsSearch()
        );
    }

    #[Route('/news/{newsId}', name: 'newsOne', methods: ['GET'])]
    public function newsOne(Request $request): Response
    {
        try {
            $news = $this->newsService->getNewsOneByRequest($request);
            return $this->json($news);
            return $this->json(
                $this->newsService->getNewsOneByRequest($request)
            );
        } catch (NewsNotFoundException $e) {
            return $this->json([
                'success' => false,
+4 −4
Original line number Diff line number Diff line
@@ -20,17 +20,17 @@ class RestaurantController extends AbstractController
    #[Route('/restaurants', name: 'restaurants', methods: ['GET'])]
    public function restaurants(RestaurantListRequest $request): Response
    {
        return $this->json($this->restaurantService->getRestaurantsByRequest($request));
        return $this->json(
            $this->restaurantService->getRestaurantsByRequest($request)
        );
    }

    #[Route('/restaurants/{restaurantId}', name: 'restaurant', methods: ['GET'])]
    public function restaurant(Request $request): Response
    {
        try {
            return new Response(
            return $this->json(
                $this->restaurantService->getRestaurantByRequest($request),
                Response::HTTP_OK,
                ['Content-Type' => 'application/json']
            );
        } catch (RestaurantNotFoundException $e) {
            return $this->json([
+3 −2
Original line number Diff line number Diff line
@@ -65,8 +65,9 @@ class NewsMapper
        );
    }

    public static function mapToNewsCategory(NewsCategory $newsCategory): NewsCategoryModel
    {
    public static function mapToNewsCategory(
        NewsCategory $newsCategory
    ): NewsCategoryModel {
        return new NewsCategoryModel(
            $newsCategory->getId(),
            $newsCategory->getName(),
+14 −10
Original line number Diff line number Diff line
@@ -53,8 +53,9 @@ class RestaurantMapper
        );
    }

    public static function mapToListElement(Restaurant $restaurant): RestaurantListingElement
    {
    public static function mapToListElement(
        Restaurant $restaurant
    ): RestaurantListingElement {
        return new RestaurantListingElement(
            $restaurant->getId(),
            $restaurant->getName(),
@@ -66,8 +67,10 @@ class RestaurantMapper
        );
    }

    public static function mapToDetailElement(Restaurant $restaurant, Collection $gallery): RestaurantDetailElement
    {
    public static function mapToDetailElement(
        Restaurant $restaurant,
        Collection $gallery
    ): RestaurantDetailElement {
        return new RestaurantDetailElement(
            $restaurant->getId(),
            $restaurant->getName(),
@@ -100,8 +103,9 @@ class RestaurantMapper
        );
    }

    public static function mapToRestaurantType(RestaurantType $restaurantType): RestaurantTypeModel
    {
    public static function mapToRestaurantType(
        RestaurantType $restaurantType
    ): RestaurantTypeModel {
        return new RestaurantTypeModel(
            $restaurantType->getId(),
            $restaurantType->getName(),
+5 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ class RestaurantRepository extends ServiceEntityRepository implements Restaurant
    ): array {
        $query = $this->createQueryBuilder('r');
        $query->select('r');

        if ($restaurantTypeId !== null) {
            $query->andWhere('r.typeId = :restaurantTypeId')
                ->setParameter('restaurantTypeId', $restaurantTypeId);
@@ -40,8 +41,10 @@ class RestaurantRepository extends ServiceEntityRepository implements Restaurant
                ->andWhere('k.id = :kitchenId')
                ->setParameter('kitchenId', $kitchenId);
        }

        $query->setMaxResults($limit)
            ->setFirstResult(($page - 1) * $limit);

        return $query->getQuery()->getResult();
    }

Loading