From 71f3e053618ec761c5b28ff524b528281a824b98 Mon Sep 17 00:00:00 2001 From: Luc Vachon Date: Thu, 12 Mar 2026 15:05:37 -0400 Subject: [PATCH 1/5] Added a rewrite function to detect schedule finder URLs and send them to the new SF2.0 page --- lib/dotcom_web/plugs/rewrite_urls.ex | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/dotcom_web/plugs/rewrite_urls.ex b/lib/dotcom_web/plugs/rewrite_urls.ex index 2a4127216b..abc2510569 100644 --- a/lib/dotcom_web/plugs/rewrite_urls.ex +++ b/lib/dotcom_web/plugs/rewrite_urls.ex @@ -25,6 +25,23 @@ defmodule DotcomWeb.Plugs.RewriteUrls do end end + # Send SF1.0 URLS to the new SF2.0 + defp rewrite_url(%{ + path_info: ["schedules", _, "line"], + params: params + }) do + route_id = params |> Map.get("route") + schedule_finder = params |> Map.get("schedule_finder", nil) + + if(!is_nil(schedule_finder)) do + direction_id = schedule_finder |> Map.get("direction_id") + stop_id = schedule_finder |> Map.get("origin") + "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}#" + else + nil + end + end + defp rewrite_url(%{path_info: ["schedules", "Boat-F3" | _]} = conn) do String.replace(conn.request_path, "Boat-F3", "Boat-F1") end From b4d2073a4a6029930c80d709d4aee2c4a1229cc3 Mon Sep 17 00:00:00 2001 From: Luc Vachon Date: Thu, 12 Mar 2026 15:20:30 -0400 Subject: [PATCH 2/5] Lint --- lib/dotcom_web/plugs/rewrite_urls.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/dotcom_web/plugs/rewrite_urls.ex b/lib/dotcom_web/plugs/rewrite_urls.ex index abc2510569..a73f0a3f35 100644 --- a/lib/dotcom_web/plugs/rewrite_urls.ex +++ b/lib/dotcom_web/plugs/rewrite_urls.ex @@ -33,12 +33,12 @@ defmodule DotcomWeb.Plugs.RewriteUrls do route_id = params |> Map.get("route") schedule_finder = params |> Map.get("schedule_finder", nil) - if(!is_nil(schedule_finder)) do + if(is_nil(schedule_finder)) do + nil + else direction_id = schedule_finder |> Map.get("direction_id") stop_id = schedule_finder |> Map.get("origin") "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}#" - else - nil end end From 09280f3d57bfe831004b4ea14a8f6661c041db2d Mon Sep 17 00:00:00 2001 From: Luc Vachon Date: Thu, 12 Mar 2026 15:58:04 -0400 Subject: [PATCH 3/5] More lint --- lib/dotcom_web/plugs/rewrite_urls.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dotcom_web/plugs/rewrite_urls.ex b/lib/dotcom_web/plugs/rewrite_urls.ex index a73f0a3f35..1e897f4909 100644 --- a/lib/dotcom_web/plugs/rewrite_urls.ex +++ b/lib/dotcom_web/plugs/rewrite_urls.ex @@ -33,7 +33,7 @@ defmodule DotcomWeb.Plugs.RewriteUrls do route_id = params |> Map.get("route") schedule_finder = params |> Map.get("schedule_finder", nil) - if(is_nil(schedule_finder)) do + if is_nil(schedule_finder) do nil else direction_id = schedule_finder |> Map.get("direction_id") From 3ddd0d759d198c665f8a50b1e573b96ea988a04a Mon Sep 17 00:00:00 2001 From: Luc Vachon Date: Mon, 16 Mar 2026 13:29:48 -0400 Subject: [PATCH 4/5] I was too stuck in javascript mindset and using the wrong syntax for argument matching wondering why it wouldn't work. This was way easier than I made it out to be. I also added logic to more smartly append rewritten URL chunks when paramaters are present. --- lib/dotcom_web/plugs/rewrite_urls.ex | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/dotcom_web/plugs/rewrite_urls.ex b/lib/dotcom_web/plugs/rewrite_urls.ex index 1e897f4909..69064bce88 100644 --- a/lib/dotcom_web/plugs/rewrite_urls.ex +++ b/lib/dotcom_web/plugs/rewrite_urls.ex @@ -28,18 +28,12 @@ defmodule DotcomWeb.Plugs.RewriteUrls do # Send SF1.0 URLS to the new SF2.0 defp rewrite_url(%{ path_info: ["schedules", _, "line"], - params: params + params: %{ + "schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id}, + "route" => route_id + } }) do - route_id = params |> Map.get("route") - schedule_finder = params |> Map.get("schedule_finder", nil) - - if is_nil(schedule_finder) do - nil - else - direction_id = schedule_finder |> Map.get("direction_id") - stop_id = schedule_finder |> Map.get("origin") - "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}#" - end + "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}" end defp rewrite_url(%{path_info: ["schedules", "Boat-F3" | _]} = conn) do @@ -55,6 +49,10 @@ defmodule DotcomWeb.Plugs.RewriteUrls do end defp merge_url(base_url, query_string) do - "#{base_url}?#{query_string}" + if base_url |> String.contains?("?") do + "#{base_url}&" <> (query_string |> String.slice(1..-1)) + else + "#{base_url}?#{query_string}" + end end end From fc4558b1d4ffaad60abdca6eb5895475c65684c6 Mon Sep 17 00:00:00 2001 From: Luc Vachon Date: Mon, 16 Mar 2026 14:02:22 -0400 Subject: [PATCH 5/5] Fixed bug in query concatination code, alphebitzed param order, wrote test for new functionality --- lib/dotcom_web/plugs/rewrite_urls.ex | 18 +++++++++-------- test/dotcom_web/plugs/rewrite_urls_test.exs | 22 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/dotcom_web/plugs/rewrite_urls.ex b/lib/dotcom_web/plugs/rewrite_urls.ex index 69064bce88..7994a0e48b 100644 --- a/lib/dotcom_web/plugs/rewrite_urls.ex +++ b/lib/dotcom_web/plugs/rewrite_urls.ex @@ -26,13 +26,15 @@ defmodule DotcomWeb.Plugs.RewriteUrls do end # Send SF1.0 URLS to the new SF2.0 - defp rewrite_url(%{ - path_info: ["schedules", _, "line"], - params: %{ - "schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id}, - "route" => route_id - } - }) do + defp rewrite_url( + %{ + path_info: ["schedules", _, "line"], + params: %{ + "route" => route_id, + "schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id} + } + } = conn + ) do "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}" end @@ -50,7 +52,7 @@ defmodule DotcomWeb.Plugs.RewriteUrls do defp merge_url(base_url, query_string) do if base_url |> String.contains?("?") do - "#{base_url}&" <> (query_string |> String.slice(1..-1)) + "#{base_url}&#{query_string}" else "#{base_url}?#{query_string}" end diff --git a/test/dotcom_web/plugs/rewrite_urls_test.exs b/test/dotcom_web/plugs/rewrite_urls_test.exs index 485a91f3db..850eb78f84 100644 --- a/test/dotcom_web/plugs/rewrite_urls_test.exs +++ b/test/dotcom_web/plugs/rewrite_urls_test.exs @@ -11,6 +11,28 @@ defmodule DotcomWeb.Plugs.RewriteUrlsTest do assert conn.halted end + test "redirects if we're going to the old schedule finder", %{conn: conn} do + route_id = Faker.Pokemon.name() + direction_id = Faker.Util.pick(["0", "1"]) + stop_id = Faker.Pokemon.name() + + conn = %{ + conn + | params: %{ + "route" => route_id, + "schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id} + }, + path_info: ["schedules", "red", "line"] + } + + conn = call(conn, []) + + assert redirected_to(conn, 302) == + "/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}" + + assert conn.halted + end + test "includes a query string if present", %{conn: conn} do conn = %{ conn