<?php
namespace App\Controller\Api;
use App\Services\Api\SharePlayerManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class SharePlayerController extends ApiController
{
/** @var SharePlayerManager $sharePlayerManager */
protected $sharePlayerManager;
/**
* @param SharePlayerManager $sharePlayerManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, SharePlayerManager $sharePlayerManager)
{
parent::__construct($em, $parameterBag);
$this->sharePlayerManager = $sharePlayerManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/share_player/add", name="api_share_player", methods={"POST"})
*/
public function add(Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataFromRequest($request);
$response = $this->sharePlayerManager->add($data, $request);
return $this->response($response);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/share_player/me", name="api_share_player_me", methods={"POST"})
*/
public function getSharePlayerMe(Request $request)
{
$request = $this->transformJsonBody($request);
$prefixFile = $this->getParameter("app.path.player_images");
$response = $this->sharePlayerManager->getSharePlayerMe($request, $prefixFile);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/share_player/delete/{id}", name="api_share_player_delete", methods={"POST"})
*/
public function delete(Int $id)
{
$response = $this->sharePlayerManager->delete($id);
return $this->response($response);
}
protected function getDataFromRequest(Request $request)
{
$data = [
"players" => $request->get('players'),
"customerShareId" => $request->get('customer_share_id'),
];
return $data;
}
}