Fix get_received_at to properly handle Packet structs
Structs don't implement the Access behaviour, so packet[:received_at] doesn't work. Use pattern matching to handle Aprsme.Packet structs separately with dot notation, and use Map.get for regular maps. This fixes the UndefinedFunctionError when rendering tracked callsign information with Packet structs from the database.
This commit is contained in:
parent
34c78fbe87
commit
6744455ac4
1 changed files with 7 additions and 2 deletions
|
|
@ -355,9 +355,14 @@ defmodule AprsmeWeb.MapLive.Components do
|
|||
"""
|
||||
end
|
||||
|
||||
# Helper function to get received_at from packet with either atom or string keys
|
||||
# Helper function to get received_at from packet (handles both structs and maps)
|
||||
defp get_received_at(%Aprsme.Packet{} = packet) do
|
||||
packet.received_at
|
||||
end
|
||||
|
||||
defp get_received_at(packet) when is_map(packet) do
|
||||
packet[:received_at] || packet["received_at"]
|
||||
# For regular maps, try both atom and string keys
|
||||
Map.get(packet, :received_at) || Map.get(packet, "received_at")
|
||||
end
|
||||
|
||||
defp get_received_at(_), do: nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue