Incident commit

This commit is contained in:
colesm 2025-04-04 08:50:54 +02:00
parent fab5249ac5
commit 8eabb71db4
3 changed files with 54 additions and 12 deletions

12
composer.lock generated
View File

@ -6671,16 +6671,16 @@
},
{
"name": "symfony/twig-bundle",
"version": "v7.1.1",
"version": "v7.1.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/twig-bundle.git",
"reference": "d48c2f08c2f315e749f0e18fc4945b7be8afe1e5"
"reference": "af902314a71fb412ae412094f7e1d7e49594507b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/twig-bundle/zipball/d48c2f08c2f315e749f0e18fc4945b7be8afe1e5",
"reference": "d48c2f08c2f315e749f0e18fc4945b7be8afe1e5",
"url": "https://api.github.com/repos/symfony/twig-bundle/zipball/af902314a71fb412ae412094f7e1d7e49594507b",
"reference": "af902314a71fb412ae412094f7e1d7e49594507b",
"shasum": ""
},
"require": {
@ -6735,7 +6735,7 @@
"description": "Provides a tight integration of Twig into the Symfony full-stack framework",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/twig-bundle/tree/v7.1.1"
"source": "https://github.com/symfony/twig-bundle/tree/v7.1.6"
},
"funding": [
{
@ -6751,7 +6751,7 @@
"type": "tidelift"
}
],
"time": "2024-05-31T14:57:53+00:00"
"time": "2024-09-25T14:20:29+00:00"
},
{
"name": "symfony/type-info",

View File

@ -2,17 +2,58 @@
namespace App\Controller;
use App\Entity\Incident;
use App\Form\IncidentType;
use App\Repository\IncidentRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/incident', name: 'incident_')]
class IncidentController extends AbstractController
{
#[Route('/incident', name: 'app_incident')]
public function index(): Response
public function __construct(
private readonly EntityManagerInterface $entityManager
) {
}
#[Route('', name: 'index', methods: ['GET'])]
public function index(IncidentRepository $incidentRepository): Response
{
return $this->render('incident/index.html.twig', [
'controller_name' => 'IncidentController',
'incidents' => $incidentRepository->findAll(),
]);
}
#[Route('/new', name: 'new', methods: ['GET', 'POST'])]
public function new(Request $request): Response
{
$incident = new Incident();
$form = $this->createForm(IncidentType::class, $incident);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($incident);
$this->entityManager->flush();
return $this->redirectToRoute('incident_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('incident/new.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/{id}', name: 'delete', methods: ['POST'])]
public function delete(Request $request, Incident $incident): Response
{
if ($this->isCsrfTokenValid('delete'.$incident->getId(), $request->request->get('_token'))) {
$this->entityManager->remove($incident);
$this->entityManager->flush();
}
return $this->redirectToRoute('incident_index', [], Response::HTTP_SEE_OTHER);
}
}

View File

@ -2,11 +2,12 @@
namespace App\Entity;
use AllowDynamicProperties;
use App\Repository\IncidentRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: IncidentRepository::class)]
#[AllowDynamicProperties] #[ORM\Entity(repositoryClass: IncidentRepository::class)]
class Incident
{
#[ORM\Id]
@ -15,7 +16,7 @@ class Incident
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $description = null;
public ?string $description = null;
#[ORM\OneToMany(targetEntity: Employee::class, mappedBy: 'incident')]
private ?Employee $employee;