src/Controller/Api/NoteExerciseController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Exercise;
  4. use App\Entity\NoteExercise;
  5. use App\Services\Api\NoteExerciseManager;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class NoteExerciseController extends ApiController
  12. {
  13.   /** @var NoteExerciseManager $noteExerciseManager */
  14.   protected $noteExerciseManager;
  15.   /**
  16.    * @param NoteExerciseManager $noteExerciseManager
  17.    */
  18.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagNoteExerciseManager $noteExerciseManager)
  19.   {
  20.     parent::__construct($em$parameterBag);
  21.     $this->noteExerciseManager $noteExerciseManager;
  22.   }
  23.   /**
  24.    * @param Request $request
  25.    * @return JsonResponse
  26.    *
  27.    * @Route("/note/exercise/{exercise}/add", name="api_note_exercise_add", methods={"POST"})
  28.    */
  29.   public function add(Exercise $exercise,Request $request)
  30.   {
  31.     $request $this->transformJsonBody($request);
  32.     $data $this->getDataFromRequest($request);
  33.     $response $this->noteExerciseManager->add($data,$exercise);
  34.     return $this->response($response);
  35.   }
  36.   /**
  37.    * @param Request $request
  38.    * @return JsonResponse
  39.    *
  40.    * @Route("/note/exercise/{noteExercise}/update", name="api_note_exercise_update", methods={"POST"})
  41.    */
  42.   public function update(Request $requestNoteExercise $noteExercise)
  43.   {
  44.     $request $this->transformJsonBody($request);
  45.     $data $this->getDataUpdateFromRequest($request);
  46.     $response $this->noteExerciseManager->update($data$noteExercise);
  47.     return $this->response($response);
  48.   }
  49.   /**
  50.    * @param Request $request
  51.    * @return JsonResponse
  52.    *
  53.    * @Route("/note/exercise/{noteExercise}", name="api_note_exercise_delete", methods={"POST"})
  54.    */
  55.   public function delete(NoteExercise $noteExercise)
  56.   {
  57.     $response $this->noteExerciseManager->delete($noteExercise);
  58.     return $this->response($response);
  59.   }
  60.   /**
  61.    * @param Request $request
  62.    * @return JsonResponse
  63.    *
  64.    * @Route("/note/exercise/{exercise}", name="api_note_exercise_get", methods={"POST"})
  65.    */
  66.   public function getNotesGame(Request $requestExercise $exercise)
  67.   {
  68.     $response $this->noteExerciseManager->getNotesGame($request$exercise);
  69.     return $this->response($response);
  70.   }
  71.   protected function getDataFromRequest(Request $request)
  72.   {
  73.     $data = [
  74.       "note" => $request->get('note'),
  75.     ];
  76.     return $data;
  77.   }
  78.   protected function getDataUpdateFromRequest(Request $request)
  79.   {
  80.     $data = [
  81.       "note" => $request->get('note'),
  82.     ];
  83.     return $data;
  84.   }
  85. }