- Ajout des favoris

This commit is contained in:
2025-01-30 11:37:05 +01:00
parent 2eaaa1d049
commit f6f7edcf34
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace App\Controller;
use App\Repository\FavorisRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\GoogleBooksService;
class FavorisController extends AbstractController
{
private GoogleBooksService $googleBooksService;
private array $favorisResult = [];
public function __construct(GoogleBooksService $googleBooksService)
{
$this->googleBooksService = $googleBooksService;
}
#[Route('/favoris', name: 'app_favoris')]
public function index(FavorisRepository $favorisRepository): Response
{
$favorisUser = $favorisRepository->findBy(['user' => $this->getUser()]);
foreach ($favorisUser as $favori) {
array_push($this->favorisResult, $this->googleBooksService->searchBooks($favori->getIdGoogle(), 'fr', 0));
}
return $this->render('favoris/index.html.twig', [
'controller_name' => 'FavorisController',
'datas' => $this->favorisResult,
]);
}
}

View File

@ -0,0 +1,19 @@
{% extends 'base.html.twig' %}
{% block title %}Mes favoris{% endblock %}
{% block body %}
<div>
{% for data in datas %}
{% if data.items is defined %}
{% for book in data.items %}
{% if book.volumeInfo.authors is defined %}
<p>{{ book.volumeInfo.title }} - {{ book.volumeInfo.authors | join(", ") }} </p>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</div>
{% endblock %}