diff --git a/src/Controller/Api/RatingController.php b/src/Controller/Api/RatingController.php index a52e6e8..69a85b2 100644 --- a/src/Controller/Api/RatingController.php +++ b/src/Controller/Api/RatingController.php @@ -3,7 +3,6 @@ namespace App\Controller\Api; use App\Entity\Rating; -use App\Entity\Restaurant; use App\Repository\RatingRepository; use App\Repository\SubjectRepository; use App\Services\OutputService; @@ -42,7 +41,7 @@ class RatingController extends AbstractController OutputService $output, SubjectRepository $subjectRepository, ): JsonResponse { - $subject = $subjectRepository->findById($request->getPayload()->get('subject_id')); + $subject = $subjectRepository->find($request->getPayload()->get('subject_id')); if ($subject === null) { return $this->json( @@ -68,7 +67,7 @@ class RatingController extends AbstractController OutputService $output, RatingRepository $ratingRepository, ): JsonResponse { - $rating = $ratingRepository->findById($id); + $rating = $ratingRepository->find($id); if ($rating === null) { return $this->json( @@ -98,7 +97,7 @@ class RatingController extends AbstractController OutputService $output, RatingRepository $ratingRepository, ): JsonResponse { - $rating = $ratingRepository->findById($id); + $rating = $ratingRepository->find($id); if ($rating === null) { return $this->json( diff --git a/src/Controller/Api/SubjectController.php b/src/Controller/Api/SubjectController.php index 57a6d41..a867763 100644 --- a/src/Controller/Api/SubjectController.php +++ b/src/Controller/Api/SubjectController.php @@ -48,11 +48,11 @@ class SubjectController extends AbstractController OutputService $output, SubjectRepository $repository, ): JsonResponse { - $subject = $repository->findById($id); + $subject = $repository->find($id); if ($subject === null) { return $this->json( - $output->error(["UNKNOWN_RATING"]) + $output->error(["UNKNOWN_SUBJECT"]) ); } @@ -74,10 +74,10 @@ class SubjectController extends AbstractController OutputService $output, SubjectRepository $repository, ): JsonResponse { - $subject = $repository->findById($id); + $subject = $repository->find($id); if ($subject === null) { - return $this->json($output->error(["UNKNOWN_RATING"])); + return $this->json($output->error(["UNKNOWN_SUBJECT"])); } $em->remove($subject); diff --git a/src/Entity/Rating.php b/src/Entity/Rating.php index 3968ed3..3cc72eb 100644 --- a/src/Entity/Rating.php +++ b/src/Entity/Rating.php @@ -58,7 +58,7 @@ class Rating return $this->note; } - public function setNote(?string $note = ''): static + public function setNote(string $note): static { $this->note = $note; diff --git a/src/Repository/RatingRepository.php b/src/Repository/RatingRepository.php index c9277ea..be99e9d 100644 --- a/src/Repository/RatingRepository.php +++ b/src/Repository/RatingRepository.php @@ -17,15 +17,6 @@ class RatingRepository extends ServiceEntityRepository parent::__construct($registry, Rating::class); } - public function findById(int $id): ?Rating - { - return $this->createQueryBuilder('r') - ->where('r.id = :id') - ->setParameter('id', $id) - ->getQuery() - ->getOneOrNullResult(); - } - /** * @return Rating[] */ @@ -37,29 +28,4 @@ class RatingRepository extends ServiceEntityRepository ->getQuery() ->getResult(); } - - // /** - // * @return Rating[] Returns an array of Rating objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('r') - // ->andWhere('r.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('r.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?Rating - // { - // return $this->createQueryBuilder('r') - // ->andWhere('r.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } } diff --git a/src/Repository/SubjectRepository.php b/src/Repository/SubjectRepository.php index 5d47894..239f5d6 100644 --- a/src/Repository/SubjectRepository.php +++ b/src/Repository/SubjectRepository.php @@ -15,38 +15,4 @@ class SubjectRepository extends ServiceEntityRepository { parent::__construct($registry, Subject::class); } - - public function findById(int $id): ?Subject - { - return $this->createQueryBuilder('s') - ->where('s.id = :id') - ->setParameter('id', $id) - ->getQuery() - ->getOneOrNullResult(); - } - - // /** - // * @return Subject[] Returns an array of Subject objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('s') - // ->andWhere('s.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('s.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?Subject - // { - // return $this->createQueryBuilder('s') - // ->andWhere('s.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } } diff --git a/tests/Application/Controller/Api/RatingControllerTest.php b/tests/Application/Controller/Api/RatingControllerTest.php index 0ff7aeb..888ded2 100644 --- a/tests/Application/Controller/Api/RatingControllerTest.php +++ b/tests/Application/Controller/Api/RatingControllerTest.php @@ -1,9 +1,8 @@ $user, ]); - static::getContainer() - ->get(SubjectRepository::class) - ->findOneBy(['name' => 'Riviera']); - $client->request( 'GET', '/api/subjects',