Minor fixes
This commit is contained in:
parent
f3d5d729bf
commit
c524592485
7 changed files with 10 additions and 86 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
namespace App\Controller\Api;
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
use App\Entity\Rating;
|
use App\Entity\Rating;
|
||||||
use App\Entity\Restaurant;
|
|
||||||
use App\Repository\RatingRepository;
|
use App\Repository\RatingRepository;
|
||||||
use App\Repository\SubjectRepository;
|
use App\Repository\SubjectRepository;
|
||||||
use App\Services\OutputService;
|
use App\Services\OutputService;
|
||||||
|
|
@ -42,7 +41,7 @@ class RatingController extends AbstractController
|
||||||
OutputService $output,
|
OutputService $output,
|
||||||
SubjectRepository $subjectRepository,
|
SubjectRepository $subjectRepository,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$subject = $subjectRepository->findById($request->getPayload()->get('subject_id'));
|
$subject = $subjectRepository->find($request->getPayload()->get('subject_id'));
|
||||||
|
|
||||||
if ($subject === null) {
|
if ($subject === null) {
|
||||||
return $this->json(
|
return $this->json(
|
||||||
|
|
@ -68,7 +67,7 @@ class RatingController extends AbstractController
|
||||||
OutputService $output,
|
OutputService $output,
|
||||||
RatingRepository $ratingRepository,
|
RatingRepository $ratingRepository,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$rating = $ratingRepository->findById($id);
|
$rating = $ratingRepository->find($id);
|
||||||
|
|
||||||
if ($rating === null) {
|
if ($rating === null) {
|
||||||
return $this->json(
|
return $this->json(
|
||||||
|
|
@ -98,7 +97,7 @@ class RatingController extends AbstractController
|
||||||
OutputService $output,
|
OutputService $output,
|
||||||
RatingRepository $ratingRepository,
|
RatingRepository $ratingRepository,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$rating = $ratingRepository->findById($id);
|
$rating = $ratingRepository->find($id);
|
||||||
|
|
||||||
if ($rating === null) {
|
if ($rating === null) {
|
||||||
return $this->json(
|
return $this->json(
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,11 @@ class SubjectController extends AbstractController
|
||||||
OutputService $output,
|
OutputService $output,
|
||||||
SubjectRepository $repository,
|
SubjectRepository $repository,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$subject = $repository->findById($id);
|
$subject = $repository->find($id);
|
||||||
|
|
||||||
if ($subject === null) {
|
if ($subject === null) {
|
||||||
return $this->json(
|
return $this->json(
|
||||||
$output->error(["UNKNOWN_RATING"])
|
$output->error(["UNKNOWN_SUBJECT"])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,10 +74,10 @@ class SubjectController extends AbstractController
|
||||||
OutputService $output,
|
OutputService $output,
|
||||||
SubjectRepository $repository,
|
SubjectRepository $repository,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$subject = $repository->findById($id);
|
$subject = $repository->find($id);
|
||||||
|
|
||||||
if ($subject === null) {
|
if ($subject === null) {
|
||||||
return $this->json($output->error(["UNKNOWN_RATING"]));
|
return $this->json($output->error(["UNKNOWN_SUBJECT"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->remove($subject);
|
$em->remove($subject);
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class Rating
|
||||||
return $this->note;
|
return $this->note;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNote(?string $note = ''): static
|
public function setNote(string $note): static
|
||||||
{
|
{
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,6 @@ class RatingRepository extends ServiceEntityRepository
|
||||||
parent::__construct($registry, Rating::class);
|
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[]
|
* @return Rating[]
|
||||||
*/
|
*/
|
||||||
|
|
@ -37,29 +28,4 @@ class RatingRepository extends ServiceEntityRepository
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->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()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,38 +15,4 @@ class SubjectRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
parent::__construct($registry, Subject::class);
|
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()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Tests\Unit\Controller\Api;
|
namespace App\Tests\Application\Controller\Api;
|
||||||
|
|
||||||
use App\Entity\Rating;
|
use App\Entity\Rating;
|
||||||
use App\Entity\Restaurant;
|
|
||||||
use App\Factory\RatingFactory;
|
use App\Factory\RatingFactory;
|
||||||
use App\Factory\RestaurantFactory;
|
use App\Factory\RestaurantFactory;
|
||||||
use App\Factory\UserFactory;
|
use App\Factory\UserFactory;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Tests\Unit\Controller\Api;
|
namespace App\Tests\Application\Controller\Api;
|
||||||
|
|
||||||
use App\Entity\Rating;
|
|
||||||
use App\Entity\Restaurant;
|
use App\Entity\Restaurant;
|
||||||
use App\Entity\Subject;
|
use App\Entity\Subject;
|
||||||
use App\Factory\RatingFactory;
|
|
||||||
use App\Factory\RestaurantFactory;
|
use App\Factory\RestaurantFactory;
|
||||||
use App\Factory\SubjectFactory;
|
use App\Factory\SubjectFactory;
|
||||||
use App\Factory\UserFactory;
|
use App\Factory\UserFactory;
|
||||||
|
|
@ -26,10 +24,6 @@ class SubjectControllerTest extends WebTestCase
|
||||||
'createdBy' => $user,
|
'createdBy' => $user,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
static::getContainer()
|
|
||||||
->get(SubjectRepository::class)
|
|
||||||
->findOneBy(['name' => 'Riviera']);
|
|
||||||
|
|
||||||
$client->request(
|
$client->request(
|
||||||
'GET',
|
'GET',
|
||||||
'/api/subjects',
|
'/api/subjects',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue