Skip to content

Commit

Permalink
wip: utility function to get stop by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Nov 4, 2024
1 parent 7577fc4 commit afb866f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/arrow/shuttles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ defmodule Arrow.Shuttles do
alias ArrowWeb.ErrorHelpers

alias Arrow.Gtfs.Route, as: GtfsRoute
alias Arrow.Gtfs.Stop, as: GtfsStop
alias Arrow.Shuttles.KML
alias Arrow.Shuttles.Shape
alias Arrow.Shuttles.ShapesUpload
alias Arrow.Shuttles.ShapeUpload
alias Arrow.Shuttles.Stop

@doc """
Returns the list of shapes.
Expand Down Expand Up @@ -331,4 +333,17 @@ defmodule Arrow.Shuttles do
query = from(r in GtfsRoute, where: r.type in [:light_rail, :heavy_rail])
Repo.all(query)
end

@doc """
Given a stop ID, returns either an Arrow-created stop, or a
stop from GTFS. Prefers the Arrow-created stop if both are
present.
"""
@spec stop_or_gtfs_stop_for_stop_id(String.t()) :: Stop.t() | GtfsStop.t() | nil
def stop_or_gtfs_stop_for_stop_id(id) do
case Repo.get(Stop, id) do
nil -> Repo.get(GtfsStop, id)
stop -> stop
end
end
end
8 changes: 8 additions & 0 deletions test/arrow/shuttles_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Arrow.ShuttlesTest do
alias Arrow.Shuttles
alias Arrow.Shuttles.Shape
import Arrow.ShuttlesFixtures
import Arrow.StopsFixtures
import Test.Support.Helpers

describe "shapes with s3 functionality enabled (mocked)" do
Expand Down Expand Up @@ -214,4 +215,11 @@ defmodule Arrow.ShuttlesTest do
assert %Ecto.Changeset{} = Shuttles.change_shuttle(shuttle)
end
end

describe "stop_or_gtfs_stop_for_stop_id/1" do
test "fetches Arrow stop" do
stop = stop_fixture()
assert ^stop = Shuttles.stop_or_gtfs_stop_for_stop_id(stop.id)
end
end
end

0 comments on commit afb866f

Please sign in to comment.