Fully implement snip db storage

This commit is contained in:
Tim
2023-12-17 01:55:26 +01:00
parent 0fce8ee4fe
commit 6107f560e2
11 changed files with 89 additions and 57 deletions

View File

@ -14,28 +14,28 @@ class HistoryController 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('history/index.html.twig', [
'snip' => $snip,
'commits' => $this->snipServiceFactory->createGit($snip)->getHistory(),
'versions' => $snipService->getVersions(),
'latestVersion' => $snipService->getLatestVersion(),
]);
}
#[Route('/set/{commit}', name: '_set')]
public function set(Snip $snip, string $commit): Response
#[Route('/set/{version}', name: '_set')]
public function set(Snip $snip, string $version): Response
{
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
$this->snipServiceFactory->createGit($snip)->setCommit($commit);
$this->addFlash('success', 'Snip version set to ' . $commit);
$this->snipServiceFactory->create($snip)->setVersion($version);
$this->addFlash('success', 'Snip version set to ' . $version);
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
}
}

View File

@ -48,7 +48,8 @@ class SnipController extends AbstractController
{
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
$snipService = $this->snipServiceFactory->createGit($snip);
$snipService = $this->snipServiceFactory->create($snip);
dump($snipService);
return $this->render('snip/single.html.twig', [
'snip' => $snip,
'content' => $pl->parse($snipService->get()),
@ -62,7 +63,7 @@ class SnipController extends AbstractController
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
$response = new Response(
$pl->clean($this->snipServiceFactory->createGit($snip)->get()),
$pl->clean($this->snipServiceFactory->create($snip)->get()),
Response::HTTP_OK,
['Content-Type' => 'text/html']
);
@ -87,13 +88,13 @@ class SnipController extends AbstractController
$form = $this->createForm(SnipType::class, $snip);
$form->add('Save', SubmitType::class);
if ($snip->getId()) {
$form->get('content')->setData($this->snipServiceFactory->createGit($snip)->get());
$form->get('content')->setData($this->snipServiceFactory->create($snip)->get());
}
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->repository->save($snip);
$this->snipServiceFactory->createGit($snip)->update($form->get('content')->getData());
$this->snipServiceFactory->create($snip)->update($form->get('content')->getData());
$this->addFlash('success', sprintf('Snip "%s" saved', $snip));
@ -126,7 +127,7 @@ class SnipController extends AbstractController
$form = $this->createForm(ConfirmationType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->snipServiceFactory->createGit($snip)->delete();
$this->snipServiceFactory->create($snip)->delete();
$this->repository->remove($snip);
$this->addFlash('success', sprintf('Snip "%s" deleted', $snip));
return $this->redirectToRoute('snip_index');