I lowkey forgot to commit
This commit is contained in:
1 parent
f9e747633f
commit
c0528310c1
54 files changed
+2154
-7
No files matched your search
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Review;
|
||||
use App\Form\ReviewType;
|
||||
use App\Repository\ReviewRepository;
|
||||
use App\Service\SpotifyClient;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Attribute\IsGranted;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/reviews')]
|
||||
class ReviewController extends AbstractController
|
||||
{
|
||||
#[Route('', name: 'review_index', methods: ['GET'])]
|
||||
public function index(ReviewRepository $reviewRepository): Response
|
||||
{
|
||||
$reviews = $reviewRepository->findLatest(50);
|
||||
return $this->render('review/index.html.twig', [
|
||||
'reviews' => $reviews,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'review_new', methods: ['GET', 'POST'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function new(Request $request): Response
|
||||
{
|
||||
$albumId = (string) $request->query->get('album_id', '');
|
||||
if ($albumId !== '') {
|
||||
return $this->redirectToRoute('album_show', ['id' => $albumId]);
|
||||
}
|
||||
$this->addFlash('info', 'Select an album first.');
|
||||
return $this->redirectToRoute('album_search');
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'review_show', requirements: ['id' => '\\d+'], methods: ['GET'])]
|
||||
public function show(Review $review): Response
|
||||
{
|
||||
return $this->render('review/show.html.twig', [
|
||||
'review' => $review,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'review_edit', requirements: ['id' => '\\d+'], methods: ['GET', 'POST'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function edit(Request $request, Review $review, EntityManagerInterface $em): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('REVIEW_EDIT', $review);
|
||||
|
||||
$form = $this->createForm(ReviewType::class, $review);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'Review updated.');
|
||||
return $this->redirectToRoute('review_show', ['id' => $review->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('review/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'review' => $review,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/delete', name: 'review_delete', requirements: ['id' => '\\d+'], methods: ['POST'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function delete(Request $request, Review $review, EntityManagerInterface $em): RedirectResponse
|
||||
{
|
||||
$this->denyAccessUnlessGranted('REVIEW_DELETE', $review);
|
||||
if ($this->isCsrfTokenValid('delete_review_' . $review->getId(), (string) $request->request->get('_token'))) {
|
||||
$em->remove($review);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'Review deleted.');
|
||||
}
|
||||
return $this->redirectToRoute('review_index');
|
||||
}
|
||||
|
||||
// fetchAlbumById no longer needed; album view handles retrieval and creation
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user