src/Controller/Api/SharePlayerController.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Services\Api\SharePlayerManager;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class SharePlayerController extends ApiController
  10. {
  11.   /** @var SharePlayerManager $sharePlayerManager */
  12.   protected $sharePlayerManager;
  13.   /**
  14.    * @param SharePlayerManager $sharePlayerManager
  15.    */
  16.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagSharePlayerManager $sharePlayerManager)
  17.   {
  18.     parent::__construct($em$parameterBag);
  19.     $this->sharePlayerManager $sharePlayerManager;
  20.   }
  21.   /**
  22.    * @param Request $request
  23.    * @return JsonResponse
  24.    *
  25.    * @Route("/share_player/add", name="api_share_player", methods={"POST"})
  26.    */
  27.   public function add(Request $request)
  28.   {
  29.     $request $this->transformJsonBody($request);
  30.     $data $this->getDataFromRequest($request);
  31.     $response $this->sharePlayerManager->add($data$request);
  32.     return $this->response($response);
  33.     return $this->response($response);
  34.   }
  35.   /**
  36.    * @param Request $request
  37.    * @return JsonResponse
  38.    *
  39.    * @Route("/share_player/me", name="api_share_player_me", methods={"POST"})
  40.    */
  41.   public function getSharePlayerMe(Request $request)
  42.   {
  43.     $request $this->transformJsonBody($request);
  44.     $prefixFile $this->getParameter("app.path.player_images");
  45.     $response $this->sharePlayerManager->getSharePlayerMe($request$prefixFile);
  46.     return $this->response($response);
  47.   }
  48.   /**
  49.    * @param Request $request
  50.    * @return JsonResponse
  51.    *
  52.    * @Route("/share_player/delete/{id}", name="api_share_player_delete", methods={"POST"})
  53.    */
  54.   public function delete(Int $id)
  55.   {
  56.     $response $this->sharePlayerManager->delete($id);
  57.     return $this->response($response);
  58.   }
  59.   protected function getDataFromRequest(Request $request)
  60.   {
  61.     $data = [
  62.       "players" => $request->get('players'),
  63.       "customerShareId" => $request->get('customer_share_id'),
  64.     ];
  65.     return $data;
  66.   }
  67. }