First fully working version of saving snips content with git control

This commit is contained in:
Tim
2023-04-04 23:23:53 +02:00
parent 1a7c9bb25a
commit 842c936d8c
12 changed files with 170 additions and 17 deletions

View File

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Snip;
use App\Form\SnipType;
use App\Repository\SnipRepository;
use App\Service\SnipServiceFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
@ -16,6 +17,7 @@ class SnipController extends AbstractController
{
public function __construct(
private readonly SnipRepository $repository,
private readonly SnipServiceFactory $snipServiceFactory,
)
{
}
@ -24,22 +26,26 @@ class SnipController extends AbstractController
public function index(): Response
{
return $this->render('snip/index.html.twig', [
'snips' => $this->repository->findAll(),
'snips' => $this->repository->findByUser($this->getUser()),
]);
}
#[Route('/singe/{snip}', name: '_single')]
#[Route('/single/{snip}', name: '_single')]
public function single(Snip $snip): Response
{
return $this->render('snip/single.html.twig', [
'snip' => $snip,
'content' => $this->snipServiceFactory->create($snip)->get(),
]);
}
#[Route('/edit/{snip}', name: '_edit')]
public function edit(Snip $snip, Request $request): Response
{
$snipService = $this->snipServiceFactory->create($snip);
$form = $this->createForm(SnipType::class, $snip);
$form->get('content')->setData($snipService->get());
$form->add('Save', SubmitType::class);
$form->handleRequest($request);
@ -47,6 +53,7 @@ class SnipController extends AbstractController
$snip->setCreatedAtTodayNoSeconds()
->setCreatedBy($this->getUser());
$this->repository->save($snip);
$snipService->update($form->get('content')->getData());
$this->addFlash('success', sprintf('Snip "%s" saved successfully', $snip));