<?php
namespace Plugin\IkusMobileApi\Controller;
use Doctrine\ORM\NonUniqueResultException;
use Eccube\Controller\AbstractController;
use Plugin\IkusMobileApi\Service\BrandService;
use Plugin\IkusMobileApi\Util\Paths;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class BrandController extends AbstractController
{
private BrandService $brandService;
public function __construct(BrandService $brandService)
{
$this->brandService = $brandService;
}
/**
* Brand API
* @Route("/api/brands", methods={"GET"})
* @param Request $request
* @return JsonResponse
*/
public function brands(Request $request): JsonResponse
{
$results = $this->brandService->findByBrands();
foreach ($results as &$result) {
if ($result['logo'] !== null) {
$result['logo'] = $request->getSchemeAndHttpHost() . Paths::UPLOAD_RICH_CATEGORY . $result['logo'];
}
}
unset($result);
return $this->json($results);
}
/**
* Brand Detail API
* @Route("/api/brand", methods={"GET"})
* @param Request $request
* @return JsonResponse
* @throws NonUniqueResultException
*/
public function detail(Request $request): JsonResponse
{
$id = $request->get('id');
$res = $this->brandService->findById($id);
if ($res['logo'] !== null) {
$res['logo'] = $request->getSchemeAndHttpHost() . Paths::UPLOAD_RICH_CATEGORY . $res['logo'];
}
if ($res['image'] !== null) {
$res['image'] = $request->getSchemeAndHttpHost() . Paths::UPLOAD_RICH_CATEGORY . $res['image'];
}
return $this->json($res);
}
}