Mostly UI stuff

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-07-09 14:19:24 +02:00
parent b60e8b7647
commit e170aa7f66
16 changed files with 450 additions and 296 deletions

View File

@@ -9,6 +9,7 @@ defmodule Eventos.Events do
alias Eventos.Events.Event
alias Eventos.Events.Comment
alias Eventos.Actors.Actor
alias Eventos.Addresses.Address
@doc """
Returns the list of events.
@@ -54,6 +55,19 @@ defmodule Eventos.Events do
)
end
import Geo.PostGIS
def find_close_events(lon, lat, radius \\ 50000) do # 50 000 meters -> 50 kms
ip_point = Geo.WKT.decode("SRID=4326;POINT(#{lon} #{lat})")
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),
preload: :organizer_actor
)
end
@doc """
Gets a single event.

View File

@@ -7,15 +7,24 @@ defmodule EventosWeb.EventController do
alias Eventos.Events
alias Eventos.Events.Event
alias Eventos.Export.ICalendar
alias Eventos.Addresses
import Logger
require Logger
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
events = Events.list_events()
render(conn, "index.json", events: events)
ip = "88.161.154.97"
Logger.debug(inspect Geolix.lookup(ip), pretty: true)
with %{city: %Geolix.Result.City{city: city, country: country, location: %Geolix.Record.Location{latitude: latitude, longitude: longitude}}} <- Geolix.lookup(ip) do
Logger.debug(inspect city)
Logger.debug(inspect [latitude, longitude])
distance = case city do
nil -> 500000
_ -> 50000
end
events = Events.find_close_events(longitude, latitude, distance)
render(conn, "index.json", events: events, coord: %{longitude: longitude, latitude: latitude, distance: distance}, city: city, country: country)
end
end
def create(conn, %{"event" => event_params}) do

View File

@@ -0,0 +1,16 @@
defmodule EventosWeb.ParticipantController do
@moduledoc """
Controller for participants to an event
"""
use EventosWeb, :controller
alias Eventos.Events
def join(conn, %{"uuid" => uuid}) do
with event <- Events.get_event_by_uuid(uuid),
%{actor: actor} <- Guardian.Plug.current_resource(conn) do
participant = Events.create_participant(%{"event_id" => event.id, "actor_id" => actor.id, "role" => 1})
render(conn, "participant.json", %{participant: participant})
end
end
end

View File

@@ -81,14 +81,12 @@ defmodule EventosWeb.Router do
patch "/events/:uuid", EventController, :update
put "/events/:uuid", EventController, :update
delete "/events/:uuid", EventController, :delete
post "/events/:uuid/join", ParticipantController, :join
post "/comments", CommentController, :create
patch "/comments/:uuid", CommentController, :update
put "/comments/:uuid", CommentController, :update
delete "/comments/:uuid", CommentController, :delete
#post "/events/:id/request", EventRequestController, :create_for_event
resources "/participant", ParticipantController
resources "/bots", BotController, except: [:new, :edit, :show, :index]
#resources "/requests", EventRequestController
post "/groups", GroupController, :create
post "/groups/:name/join", GroupController, :join
resources "/members", MemberController

View File

@@ -5,8 +5,13 @@ defmodule EventosWeb.EventView do
use EventosWeb, :view
alias EventosWeb.{EventView, ActorView, GroupView, AddressView}
def render("index.json", %{events: events}) do
%{data: render_many(events, EventView, "event_simple.json")}
def render("index.json", %{events: events, coord: coord, city: city, country: country}) do
%{
data: render_many(events, EventView, "event_simple.json"),
coord: coord,
city: city,
country: country,
}
end
def render("show_simple.json", %{event: event}) do
@@ -49,7 +54,7 @@ defmodule EventosWeb.EventView do
ends_on: event.ends_on,
uuid: event.uuid,
organizer: render_one(event.organizer_actor, ActorView, "acccount_basic.json"),
participants: render_many(event.participants, ActorView, "show_basic.json"),
participants: render_many(event.participants, ActorView, "acccount_basic.json"),
physical_address: render_one(event.physical_address, AddressView, "address.json"),
type: "Event",
address_type: event.address_type,