diff --git a/src/Monitor/Framework/Controller/ApiController.php b/src/Monitor/Framework/Controller/ApiController.php
index fceb07a..599ae2f 100644
--- a/src/Monitor/Framework/Controller/ApiController.php
+++ b/src/Monitor/Framework/Controller/ApiController.php
@@ -7,19 +7,18 @@ use App\Monitor\Action\Handler\AddMonitorHandler;
use App\Monitor\Action\Handler\DeleteMonitorHandler;
use App\Monitor\Action\Input\AddMonitorInput;
use App\Monitor\Action\Input\DeleteMonitorInput;
+use App\Util\Broadcaster;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Routing\Attribute\Route;
-use Twig\Environment;
class ApiController extends AbstractController
{
public function __construct(
- #[Autowire(service: 'twig')]
- private readonly Environment $renderer,
+ private readonly Broadcaster $broadcaster,
) {}
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
@@ -32,14 +31,10 @@ class ApiController extends AbstractController
$command->userId = $this->getUser()->getId();
$response = $handler->handle($command);
- $hub->publish(new Update(
- 'alerts',
- $this->renderer->render('broadcast/Alert.stream.html.twig', [
- 'alert_id' => uniqid(),
- 'title' => 'Success',
- 'message' => "New monitor added for {$input->title}",
- ])
- ));
+ $this->broadcaster->alert(
+ title: 'Success',
+ message: "New monitor added for {$input->title}",
+ );
return $this->json([
'status' => 200,
diff --git a/templates/broadcast/Monitor.stream.html.twig b/templates/broadcast/Monitor.stream.html.twig
index 706d277..14508a1 100644
--- a/templates/broadcast/Monitor.stream.html.twig
+++ b/templates/broadcast/Monitor.stream.html.twig
@@ -82,4 +82,10 @@
{% block remove %}
+
+
+
+
+
+
{% endblock %}