2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.SearchController do
|
2018-05-30 14:27:21 +02:00
|
|
|
@moduledoc """
|
|
|
|
Controller for Search
|
|
|
|
"""
|
2018-10-11 17:37:39 +02:00
|
|
|
use MobilizonWeb, :controller
|
2018-05-30 14:27:21 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Actors
|
2018-05-30 14:27:21 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2018-05-30 14:27:21 +02:00
|
|
|
|
|
|
|
def search(conn, %{"name" => name}) do
|
|
|
|
events = Events.find_events_by_name(name)
|
2018-07-27 10:45:35 +02:00
|
|
|
# find already saved accounts
|
|
|
|
case Actors.search(name) do
|
2018-05-30 14:27:21 +02:00
|
|
|
{:ok, actors} ->
|
|
|
|
render(conn, "search.json", events: events, actors: actors)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
|
|
|
{:error, err} ->
|
|
|
|
json(conn, err)
|
2018-05-30 14:27:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|