2018-05-30 14:27:21 +02:00
|
|
|
defmodule EventosWeb.SearchController do
|
|
|
|
@moduledoc """
|
|
|
|
Controller for Search
|
|
|
|
"""
|
|
|
|
use EventosWeb, :controller
|
|
|
|
|
|
|
|
alias Eventos.Events
|
|
|
|
alias Eventos.Actors
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
action_fallback(EventosWeb.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
|