<?php
namespace App\Controller\Api;
use App\Entity\Exercise;
use App\Entity\NoteExercise;
use App\Services\Api\NoteExerciseManager;
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 NoteExerciseController extends ApiController
{
/** @var NoteExerciseManager $noteExerciseManager */
protected $noteExerciseManager;
/**
* @param NoteExerciseManager $noteExerciseManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, NoteExerciseManager $noteExerciseManager)
{
parent::__construct($em, $parameterBag);
$this->noteExerciseManager = $noteExerciseManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note/exercise/{exercise}/add", name="api_note_exercise_add", methods={"POST"})
*/
public function add(Exercise $exercise,Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataFromRequest($request);
$response = $this->noteExerciseManager->add($data,$exercise);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note/exercise/{noteExercise}/update", name="api_note_exercise_update", methods={"POST"})
*/
public function update(Request $request, NoteExercise $noteExercise)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataUpdateFromRequest($request);
$response = $this->noteExerciseManager->update($data, $noteExercise);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note/exercise/{noteExercise}", name="api_note_exercise_delete", methods={"POST"})
*/
public function delete(NoteExercise $noteExercise)
{
$response = $this->noteExerciseManager->delete($noteExercise);
return $this->response($response);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/note/exercise/{exercise}", name="api_note_exercise_get", methods={"POST"})
*/
public function getNotesGame(Request $request, Exercise $exercise)
{
$response = $this->noteExerciseManager->getNotesGame($request, $exercise);
return $this->response($response);
}
protected function getDataFromRequest(Request $request)
{
$data = [
"note" => $request->get('note'),
];
return $data;
}
protected function getDataUpdateFromRequest(Request $request)
{
$data = [
"note" => $request->get('note'),
];
return $data;
}
}