<?php
namespace App\Controller\Api;
use App\Services\Api\NoteGameManager;
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 NoteGameController extends ApiController
{
/** @var NoteGameManager $noteGameManager */
protected $noteGameManager;
/**
* @param NoteGameManager $noteGameManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, NoteGameManager $noteGameManager)
{
parent::__construct($em, $parameterBag);
$this->noteGameManager = $noteGameManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_game/add", name="api_note_game_add", methods={"POST"})
*/
public function add(Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataFromRequest($request);
$response = $this->noteGameManager->add($data, $request);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_game/update/{id}", name="api_note_game_update", methods={"POST"})
*/
public function update(Request $request, Int $id)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataUpdateFromRequest($request);
$response = $this->noteGameManager->update($data, $id);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_game/delete/{id}", name="api_note_game_delete", methods={"POST"})
*/
public function delete(Int $id)
{
$response = $this->noteGameManager->delete($id);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note_game/{game_id}", name="api_note_game_get", methods={"POST"})
*/
public function getNotesGame(Request $request, Int $game_id)
{
$response = $this->noteGameManager->getNotesGame($request, $game_id);
return $this->response($response);
}
protected function getDataFromRequest(Request $request)
{
$data = [
"game_id" => $request->get('game_id'),
"note" => $request->get('note'),
];
return $data;
}
protected function getDataUpdateFromRequest(Request $request)
{
$data = [
"note" => $request->get('note'),
];
return $data;
}
}