<?php
namespace App\Controller\Api;
use App\Entity\Customer;
use App\Entity\NotePlayer;
use App\Entity\Player;
use App\Entity\SeasonPlayer;
use App\Services\Api\CustomerManager;
use App\Services\Api\NotePlayerManager;
use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Psr7\UploadedFile;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class NotePlayerController extends ApiController
{
/** @var NotePlayerManager $notePlayerManager */
protected $notePlayerManager;
/**
* @param NotePlayerManager $notePlayerManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, NotePlayerManager $notePlayerManager)
{
parent::__construct($em, $parameterBag);
$this->notePlayerManager = $notePlayerManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_player/add", name="api_note_player_add", methods={"POST"})
*/
public function add(Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataFromRequest($request);
$player_id = $data['player_id'];
$player = $this->em->getRepository(Player::class)->find($player_id);
$data['seasonplayer'] = $this->em->getRepository(SeasonPlayer::class)->findOneBy(['player' => $player]);
$response = $this->notePlayerManager->addNotePlayer($data, $request);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_player/update", name="api_note_player_update", methods={"POST"})
*/
public function update(Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataUpdateFromRequest($request);
$response = $this->notePlayerManager->updateNotePlayer($data, $request);
return $this->response($response);
}
// /**
// * @param Request $request
// * @return JsonResponse
// *
// * @Route("/note_player/edit", name="api_note_player_edit", methods={"POST"})
// */
// public function edit(Request $request)
// {
// $request = $this->transformJsonBody($request);
// $data = $this->getDataFromRequest($request);
// $player_id = $data['player_id'];
// $player = $this->em->getRepository(Player::class)->find($player_id);
// $data['seasonplayer'] = $this->em->getRepository(SeasonPlayer::class)->findOneBy(['player' => $player]);
// $response = $this->notePlayerManager->editNotePlayer($data, $request);
// return $this->response($response);
// }
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_player/delete/{id}", name="api_note_player_delete", methods={"POST"})
*/
public function delete($id)
{
$response = $this->notePlayerManager->deleteNotePlayer($id);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_player/{player_id}", name="api_note_player_get", methods={"POST"})
*/
public function getPlayer(Request $request, $player_id)
{
$response = $this->notePlayerManager->getNotePlayer($player_id, $request);
return $this->response($response);
}
protected function getDataFromRequest(Request $request)
{
$data = [
"player_id" => $request->get('player_id'),
"note" => $request->get('note'),
];
return $data;
}
protected function getDataUpdateFromRequest(Request $request)
{
$data = [
"player_id" => $request->get('player_id'),
"note" => $request->get('note'),
'id' => $request->get('id')
];
return $data;
}
}