Skip to content

Commit

Permalink
feat: add stop_headsign to schedules (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
boringcactus authored Nov 12, 2024
1 parent 4620ff2 commit 19899de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/mbta_v3_api/schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule MBTAV3API.Schedule do
departure_time: DateTime.t() | nil,
drop_off_type: stop_edge_type(),
pick_up_type: stop_edge_type(),
stop_headsign: String.t() | nil,
stop_sequence: integer(),
route_id: String.t(),
stop_id: String.t() | nil,
Expand All @@ -26,14 +27,23 @@ defmodule MBTAV3API.Schedule do
:departure_time,
:drop_off_type,
:pick_up_type,
:stop_headsign,
:stop_sequence,
:route_id,
:stop_id,
:trip_id
]

@impl JsonApi.Object
def fields, do: [:arrival_time, :departure_time, :drop_off_type, :pickup_type, :stop_sequence]
def fields,
do: [
:arrival_time,
:departure_time,
:drop_off_type,
:pickup_type,
:stop_headsign,
:stop_sequence
]

@impl JsonApi.Object
def includes, do: %{route: MBTAV3API.Route, stop: MBTAV3API.Stop, trip: MBTAV3API.Trip}
Expand All @@ -46,6 +56,7 @@ defmodule MBTAV3API.Schedule do
departure_time: Util.parse_optional_datetime!(item.attributes["departure_time"]),
drop_off_type: parse_stop_edge_type(item.attributes["drop_off_type"]),
pick_up_type: parse_stop_edge_type(item.attributes["pickup_type"]),
stop_headsign: item.attributes["stop_headsign"],
stop_sequence: item.attributes["stop_sequence"],
route_id: JsonApi.Object.get_one_id(item.relationships["route"]),
stop_id: JsonApi.Object.get_one_id(item.relationships["stop"]),
Expand Down
2 changes: 2 additions & 0 deletions test/mbta_v3_api/repository_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ defmodule MBTAV3API.RepositoryTest do
"id" => "schedule-60565179-70159-90",
"pickup_type" => 0,
"route_id" => "Green-B",
"stop_headsign" => nil,
"stop_id" => "70159",
"stop_sequence" => 90,
"trip_id" => "trip_1"
Expand Down Expand Up @@ -390,6 +391,7 @@ defmodule MBTAV3API.RepositoryTest do
"id" => "schedule-60565179-70159-90",
"pickup_type" => 0,
"route_id" => "Green-B",
"stop_headsign" => nil,
"stop_id" => "70159",
"stop_sequence" => 90,
"trip_id" => "trip_1"
Expand Down
2 changes: 2 additions & 0 deletions test/mbta_v3_api/schedule_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule MBTAV3API.ScheduleTest do
"departure_time" => "2024-03-13T01:07:00-04:00",
"drop_off_type" => 0,
"pickup_type" => 0,
"stop_headsign" => "abc",
"stop_sequence" => 90
},
relationships: %{
Expand All @@ -26,6 +27,7 @@ defmodule MBTAV3API.ScheduleTest do
departure_time: ~B[2024-03-13 01:07:00],
drop_off_type: :regular,
pick_up_type: :regular,
stop_headsign: "abc",
stop_sequence: 90,
route_id: "Green-D",
stop_id: "70159",
Expand Down

0 comments on commit 19899de

Please sign in to comment.