Start on removing git and better integrate db
This commit is contained in:
42
src/Controller/VersionController.php
Normal file
42
src/Controller/VersionController.php
Normal 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()]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user