Skip to content

Commit

Permalink
Finish swapping around lat and lng
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcretu committed Jul 28, 2023
1 parent 5416afb commit effe44e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Orcasite.Radio.Calculations.LongitudeLatitude do
defmodule Orcasite.Radio.Calculations.LatLng do
use Ash.Calculation

@impl true
Expand All @@ -9,7 +9,7 @@ defmodule Orcasite.Radio.Calculations.LongitudeLatitude do
@impl true
def calculate(records, _opts, _arguments) do
Enum.map(records, fn %{location_point: %{coordinates: {lng, lat}}} ->
"#{lng},#{lat}"
"#{lat},#{lng}"
end)
end
end
12 changes: 6 additions & 6 deletions server/lib/orcasite/radio/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ defmodule Orcasite.Radio.Feed do
calculations do
calculate :lat_lng,
:string,
{Orcasite.Radio.Calculations.LongitudeLatitude,
{Orcasite.Radio.Calculations.LatLng,
keys: [:location_point], select: [:location_point]}
end

defp change_lat_lng(changeset, _context) do
with {:is_string, lng_lat} when is_binary(lng_lat) <-
with {:is_string, lat_lng} when is_binary(lat_lng) <-
{:is_string, Ash.Changeset.get_argument(changeset, :lat_lng)},
{:two_els, [lng, lat]} <-
{:two_els, lng_lat |> String.split(",") |> Enum.map(&String.trim/1)},
{:two_floats, [{longitude, _}, {latitude, _}]} <-
{:two_floats, [lng, lat] |> Enum.map(&Float.parse/1)} do
{:two_els, [lat, lng]} <-
{:two_els, lat_lng |> String.split(",") |> Enum.map(&String.trim/1)},
{:two_floats, [{latitude, _}, {longitude, _}]} <-
{:two_floats, [lat, lng] |> Enum.map(&Float.parse/1)} do
changeset
|> Ash.Changeset.change_attribute(:location_point, %Geo.Point{
coordinates: {longitude, latitude},
Expand Down
2 changes: 1 addition & 1 deletion server/lib/orcasite_web/graphql/types/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule OrcasiteWeb.Types.Feed do
field :lat_lng, non_null(:json) do
resolve(fn
%{location_point: %{coordinates: {lng, lat}}}, _, _ ->
{:ok, %{lng: lng, lat: lat}}
{:ok, %{lat: lat, lng: lng}}

_, _, _ ->
{:ok, %{}}
Expand Down

0 comments on commit effe44e

Please sign in to comment.