Add test for find_close_events/4

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-12-04 12:06:34 +01:00
parent c6e6a61000
commit ace427c223
2 changed files with 19 additions and 4 deletions

View File

@@ -69,15 +69,20 @@ defmodule Mobilizon.Events do
import Geo.PostGIS
# 50 000 meters -> 50 kms
def find_close_events(lon, lat, radius \\ 50_000) do
with {:ok, ip_point} <- Geo.WKT.decode("SRID=4326;POINT(#{lon} #{lat})") do
@doc """
Find close events to coordinates
Radius is in meters and defaults to 50km.
"""
@spec find_close_events(number(), number(), number(), number()) :: list(Event.t())
def find_close_events(lon, lat, radius \\ 50_000, srid \\ 4326) do
with {:ok, point} <- Geo.WKT.decode("SRID=#{srid};POINT(#{lon} #{lat})") do
Repo.all(
from(
e in Event,
join: a in Address,
on: a.id == e.physical_address_id,
where: st_dwithin_in_meters(^ip_point, a.geom, ^radius),
where: st_dwithin_in_meters(^point, a.geom, ^radius),
preload: :organizer_actor
)
)