diff --git a/README.md b/README.md index d957331..25e50bb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ How to setup project: -- Add database credentials in `.env.local` +- Add database credentials and discog key and secret in `.env.local` - Check requirements: `symfony check:requirements` - Install dependencies: `composer install` - Create DB: `php bin/console doctrine:database:create` diff --git a/src/Controller/FavoriteController.php b/src/Controller/FavoriteController.php index 018915a..5c2caa8 100644 --- a/src/Controller/FavoriteController.php +++ b/src/Controller/FavoriteController.php @@ -2,13 +2,13 @@ namespace App\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use App\Utils; +use App\Entity\Album; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\HttpFoundation\Request; -use Doctrine\ORM\EntityManagerInterface; -use App\Entity\Album; -use App\Utils; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; #[Route('/favorite')] class FavoriteController extends AbstractController diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 41afc15..a9de71e 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -2,9 +2,9 @@ namespace App\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class IndexController extends AbstractController { diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 928d848..dd05627 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -2,25 +2,29 @@ namespace App\Controller; -use App\Entity\Album; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\HttpFoundation\Request; -use Doctrine\ORM\EntityManagerInterface; use App\Utils; +use App\Entity\Album; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SearchController extends AbstractController { private static function addFruitToAlbums(array $releases, string $fruit, EntityManagerInterface $entityManager): void { + $albums = $entityManager->getRepository(Album::class)->findAll(); foreach ($releases as $release) { + $album = null; $id = $release["id"]; - $album = $entityManager->getRepository(Album::class)->findBy( - ['album_id' => $id] - ); - if (count($album) == 0) { + foreach($albums as $remote_album){ + if ($remote_album->getAlbumId() == $id) + $album == $remote_album; + break; + } + if ($album == null) { $album = new Album(); $album->setAlbumId($id); //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database @@ -33,8 +37,8 @@ class SearchController extends AbstractController //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database } $entityManager->persist($album); - $entityManager->flush(); } + $entityManager->flush(); } private static function getEmojiName(string | null $emoji): string | null diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php deleted file mode 100644 index 76bf5c4..0000000 --- a/src/Controller/SecurityController.php +++ /dev/null @@ -1,32 +0,0 @@ -getLastAuthenticationError(); - - // last username entered by the user - $lastUsername = $authenticationUtils->getLastUsername(); - - return $this->render('security/login.html.twig', [ - 'last_username' => $lastUsername, - 'error' => $error, - ]); - } - - #[Route(path: '/logout', name: 'app_logout')] - public function logout(): void - { - throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); - } -} diff --git a/src/Controller/TestController.php b/src/Controller/TestController.php deleted file mode 100644 index 21e3f65..0000000 --- a/src/Controller/TestController.php +++ /dev/null @@ -1,16 +0,0 @@ - $form->createView(), ], new Response(null, 422)); } + + + #[Route(path: '/login', name: 'app_login')] + public function login(AuthenticationUtils $authenticationUtils): Response + { + // get the login error if there is one + $error = $authenticationUtils->getLastAuthenticationError(); + + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', [ + 'last_username' => $lastUsername, + 'error' => $error, + ]); + } + + #[Route(path: '/logout', name: 'app_logout')] + public function logout(): void + { + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + } } diff --git a/src/Entity/ApiDiscog.php b/src/Entity/ApiDiscog.php deleted file mode 100644 index f76ae59..0000000 --- a/src/Entity/ApiDiscog.php +++ /dev/null @@ -1,20 +0,0 @@ -id; - } -} diff --git a/src/Repository/ApiDiscogRepository.php b/src/Repository/ApiDiscogRepository.php deleted file mode 100644 index 0f0b17d..0000000 --- a/src/Repository/ApiDiscogRepository.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @method ApiDiscog|null find($id, $lockMode = null, $lockVersion = null) - * @method ApiDiscog|null findOneBy(array $criteria, array $orderBy = null) - * @method ApiDiscog[] findAll() - * @method ApiDiscog[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class ApiDiscogRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, ApiDiscog::class); - } - -// /** -// * @return ApiDiscog[] Returns an array of ApiDiscog objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('a') -// ->andWhere('a.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('a.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?ApiDiscog -// { -// return $this->createQueryBuilder('a') -// ->andWhere('a.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -}