app/Plugin/IkusMobileApi/Controller/ProductController.php line 64

Open in your IDE?
  1. <?php /** @noinspection ALL */
  2. namespace Plugin\IkusMobileApi\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use PHPUnit\Util\Json;
  5. use Plugin\IkusMobileApi\Service\ProductService;
  6. use Plugin\IkusMobileApi\Util\Paths;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class ProductController extends AbstractController
  11. {
  12.     private ProductService $productService;
  13.     public function __construct(ProductService $productService)
  14.     {
  15.         $this->productService $productService;
  16.     }
  17.     /**
  18.      * Search API
  19.      * @Route("/api/products/search", methods={"GET"})
  20.      * @param Request $request
  21.      * @return JsonResponse
  22.      */
  23.     public function search(Request $request)
  24.     {
  25.         $results $this->productService->search($request->query->all());
  26.         return $this->json($this->formatList($request$results));
  27.     }
  28.     /**
  29.      * Ranking API
  30.      * @Route("/api/products/ranking", methods={"GET"})
  31.      * @param Request $request
  32.      * @return JsonResponse
  33.      */
  34.     public function ranking(Request $request): JsonResponse
  35.     {
  36.         $results $this->productService->findByRanking();
  37.         return $this->json($this->formatList($request$results));
  38.     }
  39.     /**
  40.      * PickUp API
  41.      * @Route("/api/products/pickUp", methods={"GET"})
  42.      * @param Request $request
  43.      * @return JsonResponse
  44.      */
  45.     public function pickUp(Request $request): JsonResponse
  46.     {
  47.         $results $this->productService->findByPickUp();
  48.         return $this->json($this->formatList($request$results));
  49.     }
  50.     /**
  51.      * Checked API
  52.      * @Route("/api/products/checked", methods={"GET"})
  53.      * @param Request $request
  54.      * @return JsonResponse
  55.      */
  56.     public function checked(Request $request): JsonResponse
  57.     {
  58.         $ids $request->query->get('ids');
  59.         if (!is_array($ids)) {
  60.             return $this->json([]);
  61.         }
  62.         $results $this->productService->findByIds($ids);
  63.         return $this->json($this->formatList($request$results));
  64.     }
  65.     /**
  66.      * カテゴリー内の商品が持つ検索条件取得API
  67.      * @Route("/api/product/styleFilters", methods={"GET"})
  68.      * @param Request $request
  69.      * @return JsonResponse
  70.      */
  71.     public function styleFilters(Request $request): JsonResponse
  72.     {
  73.         $category_id $request->get('category_id');
  74.         $results $this->productService->findStyleFilters($category_id);
  75.         return $this->json($results);
  76.     }
  77.     private function formatList(Request $request$results)
  78.     {
  79.         foreach ($results as &$result) {
  80.             $result['min_price'] = intval($result['min_price']);
  81.             $result['max_price'] = intval($result['max_price']);
  82.             if ($result['image'] !== null) {
  83.                 $result['image'] = $request->getSchemeAndHttpHost() . Paths::UPLOAD_SAVE_IMAGE $result['image'];
  84.             }
  85.         }
  86.         unset($result);
  87.         return $results;
  88.     }
  89. }