diff --git a/api/src/Controller/FruitController.php b/api/src/Controller/FruitController.php index a6a8c7b..1da6de0 100644 --- a/api/src/Controller/FruitController.php +++ b/api/src/Controller/FruitController.php @@ -133,6 +133,19 @@ public function fruit(Request $request, FruitRepository $fruits) } } + /** + * Get all favorites + * + * @param \App\Repository\FavoriteRepository $favorites + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + #[Route('/favorites', name: 'favorite.all', methods: ['GET'])] + public function favorites(FavoriteRepository $favorites) + { + return $this->json($favorites->all()); + } + /** * Add fruit to favorites * diff --git a/api/src/Repository/FavoriteRepository.php b/api/src/Repository/FavoriteRepository.php index 71dee5c..948ebc1 100644 --- a/api/src/Repository/FavoriteRepository.php +++ b/api/src/Repository/FavoriteRepository.php @@ -21,28 +21,37 @@ public function __construct(ManagerRegistry $registry) parent::__construct($registry, Favorite::class); } -// /** -// * @return Favorite[] Returns an array of Favorite objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('f') -// ->andWhere('f.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('f.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } + public function all() + { + return $this->createQueryBuilder('f') + ->select('f.id', 'f.dateAdded', 'fruit.id as fruit_id', 'fruit.name as fruit_name') + ->leftJoin('f.fruit', 'fruit') + ->getQuery() + ->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); + } + + // /** + // * @return Favorite[] Returns an array of Favorite objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('f') + // ->andWhere('f.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('f.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } -// public function findOneBySomeField($value): ?Favorite -// { -// return $this->createQueryBuilder('f') -// ->andWhere('f.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } + // public function findOneBySomeField($value): ?Favorite + // { + // return $this->createQueryBuilder('f') + // ->andWhere('f.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } } diff --git a/app/src/views/Form.vue b/app/src/views/Form.vue index a3d67ec..111443f 100644 --- a/app/src/views/Form.vue +++ b/app/src/views/Form.vue @@ -2,6 +2,10 @@