Skip to content

Commit

Permalink
handle nil
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed May 1, 2024
1 parent 1af2e10 commit 6eaa4f6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/dotcom_web/controllers/schedule/line_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule DotcomWeb.ScheduleController.LineApi do
alias DotcomWeb.ScheduleController.{Green, Predictions, VehicleTooltips, VehicleLocations}
alias Dotcom.TransitNearMe
alias DotcomWeb.ScheduleController.Line.Helpers, as: LineHelpers
alias Stops.Stop
alias Vehicles.Vehicle

@typep simple_vehicle :: %{
Expand Down Expand Up @@ -102,7 +103,7 @@ defmodule DotcomWeb.ScheduleController.LineApi do
tooltips_by_stop =
tooltips
|> Map.values()
|> Enum.group_by(&(Stops.Repo.get_parent(&1.vehicle.stop_id) |> Map.get(:id)))
|> Enum.group_by(&group_tooltips/1)

combined_data_by_stop =
Map.keys(headsigns_by_stop)
Expand All @@ -124,6 +125,13 @@ defmodule DotcomWeb.ScheduleController.LineApi do
Jason.encode!(combined_data_by_stop)
end

defp group_tooltips(tooltip) do
case Stops.Repo.get_parent(tooltip.vehicle.stop_id) do
%Stop{id: id} -> id
_ -> nil
end
end

@spec simple_vehicle_map(VehicleTooltip.t()) :: simple_vehicle
defp simple_vehicle_map(
%VehicleTooltip{
Expand Down

0 comments on commit 6eaa4f6

Please sign in to comment.