Start on removing git and better integrate db

This commit is contained in:
Tim
2023-12-18 01:26:44 +01:00
parent dd55126ac2
commit 64bd7e3642
17 changed files with 58 additions and 304 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\Controller;
use App\Entity\Snip;
use App\Entity\SnipContent;
use App\Security\Voter\SnipVoter;
use App\Service\SnipServiceFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/version/{snip}', name: 'version')]
class VersionController extends AbstractController
{
public function __construct(
private readonly SnipServiceFactory $snipServiceFactory,
) {}
#[Route('/', name: '_index')]
public function index(Snip $snip): Response
{
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
$snipService = $this->snipServiceFactory->create($snip);
return $this->render('version/index.html.twig', [
'snip' => $snip,
'versions' => $snipService->getVersions(),
'latestVersion' => $snipService->getLatestVersion(),
]);
}
#[Route('/set/{version}', name: '_set')]
public function set(Snip $snip, SnipContent $version): Response
{
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
$this->snipServiceFactory->create($snip)->setVersion($version->getId());
$this->addFlash('success', 'Snip version set to ' . $version->getId());
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
}
}