Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • 2023
  • branche-avec-truc-style
  • branche-a-rebase
4 results

solutions.md

Blame
  • DefaultController.php 4.84 KiB
    <?php
    
    namespace ApiBundle\Controller;
    
    use BackendBundle\Entity\Device;
    use FOS\RestBundle\View\View;
    use FOS\RestBundle\Controller\Annotations\Get;
    use FOS\RestBundle\Controller\Annotations\Post;
    use FOS\RestBundle\Controller\FOSRestController;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    
    class DefaultController extends FOSRestController
    {
        /**
         * @return Response
         */
        public function getPredictionsAction()
        {
            $view = View::create()
                ->setStatusCode(200)
                ->setData($this->getPredictionRepository()->findAll());
    
            return $this->handleView($view);
    
        }
    
        /**
         * @return Response
         */
        public function getLeaguesAction()
        {
            $view = View::create()
                ->setStatusCode(200)
                ->setData($this->getLeagueRepository()->findAll());
    
            return $this->handleView($view);
    
        }
    
        /**
         * @return Response
         */
        public function getPacksAction()
        {
            $view = View::create()
                ->setStatusCode(200)
                ->setData($this->getPackRepository()->findAll());
    
            return $this->handleView($view);
    
        }
    
        /**
         * @param int $id
         * @return Response
         *
         * GET Route annotation.
         * @Get("/predictions/league/{id}")
         */
        public function getPredictionsByLeagueAction(int $id)
        {
            $league = $this->getLeagueRepository()->find($id);
    
            $view = View::create();
    
            if ($league) {
                $view->setStatusCode(200);
                $view->setData($this->getPredictionRepository()->findBy([
                    'league' => $league