feat: dynamically manage floors/rooms/tags

This commit is contained in:
2026-04-16 16:57:45 +02:00
parent 34ddbe669e
commit c3fd8b950c
11 changed files with 238 additions and 22 deletions
@@ -0,0 +1,43 @@
defmodule Localiser.Localisation.Floor.Manager do
@moduledoc """
Global GenServer that reacts to floor lifecycle events and drives Floor.Supervisor.
- {:floor_created, floor} → start a Floor.Server for the new floor
- {:floor_deleted, floor_id} → terminate the Floor.Server subtree
"""
use GenServer
alias Localiser.Localisation.Floor
def start_link(_args) do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
@impl true
def init(:ok) do
Phoenix.PubSub.subscribe(Localiser.PubSub, "floors")
{:ok, :ok}
end
@impl true
def handle_info({:floor_created, floor}, state) do
case Registry.lookup(Localiser.Registry, {:floor_server, floor.id}) do
[] -> Floor.Supervisor.start_floor_server(floor)
_ -> :ok
end
{:noreply, state}
end
def handle_info({:floor_deleted, floor_id}, state) do
case Registry.lookup(Localiser.Registry, {:floor_server, floor_id}) do
[{pid, _}] -> DynamicSupervisor.terminate_child(Floor.Supervisor, pid)
[] -> :ok
end
{:noreply, state}
end
def handle_info(_msg, state), do: {:noreply, state}
end