From 6d63638312bf8b632b67c7e8721278714f8fe789 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 22 Mar 2026 13:11:02 -0500 Subject: [PATCH] Remove dead code - unused controller actions All pages are already LiveView, so removed: - InfoController (replaced by InfoLive.Show) - PageController.home and .packets (unused functions) Remaining PageController functions are health/status JSON endpoints only. All user-facing pages use LiveView with proper session continuity. --- lib/aprsme_web/controllers/info_controller.ex | 104 ------------------ lib/aprsme_web/controllers/page_controller.ex | 8 -- 2 files changed, 112 deletions(-) delete mode 100644 lib/aprsme_web/controllers/info_controller.ex diff --git a/lib/aprsme_web/controllers/info_controller.ex b/lib/aprsme_web/controllers/info_controller.ex deleted file mode 100644 index c087506..0000000 --- a/lib/aprsme_web/controllers/info_controller.ex +++ /dev/null @@ -1,104 +0,0 @@ -defmodule AprsmeWeb.InfoController do - use AprsmeWeb, :controller - - alias Aprsme.Packets - alias AprsmeWeb.Live.Shared.PacketUtils - - @neighbor_radius_km 10 - @neighbor_limit 10 - - def show(conn, %{"callsign" => callsign}) do - normalized_callsign = String.upcase(String.trim(callsign)) - packet = get_latest_packet(normalized_callsign) - neighbors = get_neighbors(packet, normalized_callsign) - - render(conn, :show, - callsign: normalized_callsign, - packet: packet, - neighbors: neighbors, - page_title: "APRS station #{normalized_callsign}" - ) - end - - defp get_latest_packet(callsign) do - %{callsign: callsign, limit: 1} - |> Packets.get_recent_packets() - |> List.first() - end - - defp get_neighbors(nil, _callsign), do: [] - - defp get_neighbors(packet, callsign) do - lat = packet.lat - lon = packet.lon - - if is_nil(lat) or is_nil(lon) do - [] - else - # Simple bounding box for ~10km radius - delta = @neighbor_radius_km / 111.0 - min_lat = lat - delta - max_lat = lat + delta - min_lon = lon - delta - max_lon = lon + delta - opts = %{bounds: [min_lon, min_lat, max_lon, max_lat], limit: 50} - - opts - |> Packets.get_recent_packets() - |> Enum.filter(fn p -> - (p.sender != callsign and p.lat) && p.lon - end) - |> uniq_by(& &1.sender) - |> Enum.map(fn p -> - dist = haversine(lat, lon, p.lat, p.lon) - - %{ - callsign: p.sender, - distance: format_distance(dist), - last_heard: PacketUtils.get_timestamp(p), - packet: p - } - end) - |> Enum.sort_by(& &1.distance) - |> Enum.take(@neighbor_limit) - end - end - - defp uniq_by(list, fun) do - list - |> Enum.reduce({MapSet.new(), []}, fn item, {set, acc} -> - key = fun.(item) - - if MapSet.member?(set, key) do - {set, acc} - else - {MapSet.put(set, key), [item | acc]} - end - end) - |> elem(1) - |> Enum.reverse() - end - - defp haversine(lat1, lon1, lat2, lon2) do - # Returns distance in km - r = 6371 - dlat = :math.pi() / 180 * (lat2 - lat1) - dlon = :math.pi() / 180 * (lon2 - lon1) - - a = - :math.sin(dlat / 2) * :math.sin(dlat / 2) + - :math.cos(:math.pi() / 180 * lat1) * :math.cos(:math.pi() / 180 * lat2) * - :math.sin(dlon / 2) * :math.sin(dlon / 2) - - c = 2 * :math.atan2(:math.sqrt(a), :math.sqrt(1 - a)) - r * c - end - - defp format_distance(km) when km < 1.0 do - "#{Float.round(km * 1000, 0)} m" - end - - defp format_distance(km) do - "#{Float.round(km, 2)} km" - end -end diff --git a/lib/aprsme_web/controllers/page_controller.ex b/lib/aprsme_web/controllers/page_controller.ex index c0ece15..ee2d644 100644 --- a/lib/aprsme_web/controllers/page_controller.ex +++ b/lib/aprsme_web/controllers/page_controller.ex @@ -4,14 +4,6 @@ defmodule AprsmeWeb.PageController do alias Aprsme.Cluster.LeaderElection - def home(conn, _params) do - render(conn, :home) - end - - def packets(conn, _params) do - render(conn, :packets) - end - def health(conn, _params) do # Use our health check plug logic health_status = Application.get_env(:aprsme, :health_status, :healthy)