Skip to content

Commit

Permalink
feat(ex/skate/open_route_service_api): send 40ft bus info to ORS for …
Browse files Browse the repository at this point in the history
…HGV profile routing (#2507)

* feat(ex/skate/open_route_service_api): send 40ft bus info to ORS for HGV profile routing

* cleanup(ex/skate/open_route_service_api): make API options typed

* cleanup(ex/skate/open_route_service_api): move 40ft bus profile into function
  • Loading branch information
firestack authored Mar 18, 2024
1 parent 37942ba commit cf7612c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
37 changes: 35 additions & 2 deletions lib/skate/open_route_service_api/directions_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,46 @@ defmodule Skate.OpenRouteServiceAPI.DirectionsRequest do
"""
@derive Jason.Encoder

defmodule Options do
@moduledoc false
defmodule ProfileParams do
@moduledoc false
defmodule HgvRestrictions do
@moduledoc false
@type t :: %{length: float(), width: float(), height: float()}
defstruct [:length, :width, :height]

def bus_40ft,
do: %{
length: 12.192,
width: 3.2004,
height: 3.5052
}
end

@type t :: %{restrictions: HgvRestrictions.t()}
defstruct [:restrictions]
end

@type t :: %{profile_params: ProfileParams.t()}
defstruct [:profile_params]
end

@typedoc """
Type that represents a request made to OpenRouteService's Directions API
"""
@type t() :: %__MODULE__{
coordinates: [[float()]],
continue_straight: boolean()
continue_straight: boolean(),
options: Options.t()
}

defstruct coordinates: [], continue_straight: true
defstruct coordinates: [],
continue_straight: true,
options: %{
profile_params: %{
restrictions:
Skate.OpenRouteServiceAPI.DirectionsRequest.Options.ProfileParams.HgvRestrictions.bus_40ft()
}
}
end
6 changes: 6 additions & 0 deletions test/skate_web/controllers/detour_route_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ defmodule SkateWeb.DetourRouteControllerTest do
assert args.coordinates == [[0, 0], [1, 1]]
assert args.continue_straight == true

assert %{
length: 12.192,
width: 3.2004,
height: 3.5052
} = args.options.profile_params.restrictions

{:ok, build(:ors_directions_json)}
end)

Expand Down

0 comments on commit cf7612c

Please sign in to comment.