Newer
Older
use App\Requests\{
SortPriceRequest,
SearchRequest,
UniqElementsRequest,
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
#[Route('/sortPrice', name: 'sortPrice', methods: ['POST'])]
public function sortPrice(SortPriceRequest $request): Response
$array = $this->functions->sortPrice($request->getRequest()->toArray()['items']);
#[Route('/search', name: 'search', methods: ['POST'])]
public function search(SearchRequest $request): Response
$array = $request->getRequest()->toArray()['items'];
$id = $request->getRequest()->query->get('id');
$result = $this->functions->search($array, $id);
return $this->json($result);
#[Route('/uniqElements', name: 'uniqElements', methods: ['POST'])]
public function uniqElements(UniqElementsRequest $request): Response
$result = $this->functions->uniqElements($request->getRequest()->toArray()['items']);
#[Route('/prepareMenu', name: 'prepareMenu', methods: ['POST'])]
public function prepareMenu(MenuRequest $request): Response
$result = $this->functions->prepareMenu($request->getRequest()->toArray()['items']);
#[Route('/howDaysToNy', name: 'howDaysToNy', methods: ['GET'])]
public function howDaysToNy(HowDaysToNyRequest $request): Response
$result = $this->functions->howDaysToNy(new DateTimeImmutable($date));
} catch (\Exception $e) {
return new Response($e->getMessage());
}
return $this->json(["Days before NY:" => $result]);