mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
Re-open the same ticket if a ticket already exists with the same externalRef, instead of creating a new one
This commit is contained in:
parent
45828174d1
commit
2d8b960d9e
@ -15,6 +15,7 @@ use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand;
|
||||
use Chill\TicketBundle\Action\Ticket\Handler\AssociateByPhonenumberCommandHandler;
|
||||
use Chill\TicketBundle\Action\Ticket\CreateTicketCommand;
|
||||
use Chill\TicketBundle\Action\Ticket\Handler\CreateTicketCommandHandler;
|
||||
use Chill\TicketBundle\Repository\TicketRepositoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -31,7 +32,8 @@ final readonly class CreateTicketController
|
||||
private AssociateByPhonenumberCommandHandler $associateByPhonenumberCommandHandler,
|
||||
private Security $security,
|
||||
private UrlGeneratorInterface $urlGenerator,
|
||||
private EntityManagerInterface $entityManager
|
||||
private EntityManagerInterface $entityManager,
|
||||
private TicketRepositoryInterface $ticketRepository,
|
||||
) {}
|
||||
|
||||
#[Route('{_locale}/ticket/ticket/create')]
|
||||
@ -41,6 +43,14 @@ final readonly class CreateTicketController
|
||||
throw new AccessDeniedHttpException('Only users are allowed to create tickets.');
|
||||
}
|
||||
|
||||
if ('' !== $extId = $request->query->get('extId', '')) {
|
||||
if (null !== $ticket = $this->ticketRepository->findOneByExternalRef($extId)) {
|
||||
return new RedirectResponse(
|
||||
$this->urlGenerator->generate('chill_ticket_ticket_edit', ['id' => $ticket->getId()])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$createCommand = new CreateTicketCommand($request->query->get('extId', ''));
|
||||
$ticket = $this->createTicketCommandHandler->__invoke($createCommand);
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\TicketBundle\Repository;
|
||||
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final readonly class TicketRepository implements TicketRepositoryInterface
|
||||
{
|
||||
private ObjectRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $objectManager)
|
||||
{
|
||||
$this->repository = $objectManager->getRepository($this->getClassName());
|
||||
}
|
||||
|
||||
public function find($id): ?Ticket
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?Ticket
|
||||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return Ticket::class;
|
||||
}
|
||||
|
||||
public function findOneByExternalRef(string $extId): ?Ticket
|
||||
{
|
||||
return $this->repository->findOneBy(['externalRef' => $extId]);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\TicketBundle\Repository;
|
||||
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
/**
|
||||
* @extends ObjectRepository<Ticket>
|
||||
*/
|
||||
interface TicketRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
public function findOneByExternalRef(string $extId): ?Ticket;
|
||||
}
|
@ -3,13 +3,16 @@ services:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
|
||||
Chill\TicketBundle\Action\Ticket\Handler\:
|
||||
resource: '../Action/Ticket/Handler/'
|
||||
|
||||
Chill\TicketBundle\Controller\:
|
||||
resource: '../Controller/'
|
||||
tags:
|
||||
- controller.service_arguments
|
||||
|
||||
Chill\TicketBundle\Action\Ticket\Handler\:
|
||||
resource: '../Action/Ticket/Handler/'
|
||||
Chill\TicketBundle\Repository\:
|
||||
resource: '../Repository/'
|
||||
|
||||
Chill\TicketBundle\Serializer\:
|
||||
resource: '../Serializer/'
|
||||
|
Loading…
x
Reference in New Issue
Block a user