WIP first try for sending update command for ticket

This commit is contained in:
Julien Fastré 2025-07-16 10:56:35 +02:00
parent 41896b1dd4
commit def75cec6c
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -15,13 +15,18 @@ use Chill\TicketBundle\Action\Ticket\ChangeEmergencyStateCommand;
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
use Chill\TicketBundle\Entity\Ticket;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
/**
* Handler for changing the emergency status of a ticket.
*/
class ChangeEmergencyStateCommandHandler
{
public function __construct(private readonly ClockInterface $clock) {}
public function __construct(
private readonly ClockInterface $clock,
private readonly HubInterface $hub,
) {}
public function __invoke(Ticket $ticket, ChangeEmergencyStateCommand $command): Ticket
{
@ -38,12 +43,20 @@ class ChangeEmergencyStateCommandHandler
}
// Create a new emergency status history with the new status
new EmergencyStatusHistory(
$emergency = new EmergencyStatusHistory(
$command->newEmergencyStatus,
$ticket,
$this->clock->now(),
);
$this->hub->publish(
new Update(
sprintf('https//chill.social/ticket/%d', $ticket->getId()),
json_encode(['emergency' => $emergency->getEmergencyStatus()]),
private: true
)
);
return $ticket;
}
}