src/Controller/Api/PlayerWeightController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Player;
  4. use App\Entity\PlayerWeight;
  5. use App\Services\Api\PlayerWeightManager;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class PlayerWeightController extends ApiController
  12. {
  13.   /** @var PlayerWeightManager $playerWeightManager */
  14.   protected $playerWeightManager;
  15.   /**
  16.    * @param PlayerWeightManager $playerWeightManager
  17.    */
  18.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagPlayerWeightManager $playerWeightManager)
  19.   {
  20.     parent::__construct($em$parameterBag);
  21.     $this->playerWeightManager $playerWeightManager;
  22.   }
  23.   /**
  24.    * @param Request $request
  25.    * @return JsonResponse
  26.    *
  27.    * @Route("/player_weight/{player}/add", name="api_player_weight_add", methods={"POST"})
  28.    */
  29.   public function add(Request $requestPlayer $player)
  30.   {
  31.     $request $this->transformJsonBody($request);
  32.     $data $this->getDataFromRequest($request);
  33.     $response $this->playerWeightManager->add($data$player);
  34.     return $this->response($response);
  35.   }
  36.   /**
  37.    * @param Request $request
  38.    * @return JsonResponse
  39.    *
  40.    * @Route("/player_weight/{playerWeight}/update", name="api_player_weight_update", methods={"POST"})
  41.    */
  42.   public function update(Request $requestPlayerWeight $playerWeight)
  43.   {
  44.     $request $this->transformJsonBody($request);
  45.     $data $this->getDataFromRequest($request);
  46.     $response $this->playerWeightManager->update($data$playerWeight);
  47.     return $this->response($response);
  48.   }
  49.   /**
  50.    * @param Request $request
  51.    * @return JsonResponse
  52.    *
  53.    * @Route("/player_weight/{weight}/delete", name="api_player_weight_delete", methods={"POST"})
  54.    */
  55.   public function delete(PlayerWeight $weight)
  56.   {
  57.     $response $this->playerWeightManager->delete($weight);
  58.     return $this->response($response);
  59.   }
  60.   protected function getDataFromRequest(Request $request)
  61.   {
  62.     $data = [
  63.       "weight" => $request->get('weight'),
  64.       "date" => $request->get('date'),
  65.       "time" => $request->get('time'),
  66.     ];
  67.     return $data;
  68.   }
  69. }