wip-feat: adds functionality to Monitor button

This commit is contained in:
2025-05-08 22:48:25 -05:00
parent b93da3df1d
commit 5ff9842eaa
7 changed files with 169 additions and 13 deletions

View File

@@ -5,16 +5,37 @@ namespace App\Download\Framework\Controller;
use App\Download\Action\Handler\AddMonitorHandler;
use App\Download\Action\Input\AddMonitorInput;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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
{
#[Route('/monitor', name: 'app_add_movie_monitor', methods: ['POST'])]
public function __construct(
#[Autowire(service: 'twig')]
private readonly Environment $renderer,
private readonly HubInterface $hub,
) {}
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
public function addMonitor(
AddMonitorInput $input,
AddMonitorHandler $handler,
HubInterface $hub,
) {
$response = $handler->handle($input->toCommand());
$hub->publish(new Update(
'alerts',
$this->renderer->render('broadcast/Alert.html.twig', [
'alert_id' => uniqid(),
'title' => 'Success',
'message' => "New monitor added for {$input->title}",
])
));
return $this->json([
'status' => 200,
'message' => $response

View File

@@ -6,6 +6,8 @@ use App\Download\Framework\Repository\MonitorRepository;
use App\User\Framework\Entity\User;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Ignore;
use Symfony\Component\Serializer\Attribute\MaxDepth;
#[ORM\Entity(repositoryClass: MonitorRepository::class)]
class Monitor
@@ -15,6 +17,7 @@ class Monitor
#[ORM\Column]
private ?int $id = null;
#[Ignore]
#[ORM\ManyToOne(inversedBy: 'yes')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;