@@ -20,10 +20,11 @@ defmodule EventosWeb.ActorController do
|
||||
render(conn, "show.json", actor: actor)
|
||||
end
|
||||
|
||||
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
||||
def search(conn, %{"name" => name}) do
|
||||
with {:ok, actor} <- ActivityPub.make_actor_from_nickname(name) do
|
||||
render(conn, "acccount_basic.json", actor: actor)
|
||||
else
|
||||
case Actors.search(name) do # find already saved accounts
|
||||
{:ok, actors} ->
|
||||
render(conn, "index.json", actors: actors)
|
||||
{:error, err} -> json(conn, err)
|
||||
end
|
||||
end
|
||||
|
||||
46
lib/eventos_web/controllers/bot_controller.ex
Normal file
46
lib/eventos_web/controllers/bot_controller.ex
Normal file
@@ -0,0 +1,46 @@
|
||||
defmodule EventosWeb.BotController do
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Actors
|
||||
alias Eventos.Actors.Bot
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
bots = Actors.list_bots()
|
||||
render(conn, "index.json", bots: bots)
|
||||
end
|
||||
|
||||
def create(conn, %{"bot" => bot_params}) do
|
||||
with user <- Guardian.Plug.current_resource,
|
||||
bot_params <- Map.put(bot_params, "user_id", user.id),
|
||||
{:ok, actor } <- Actors.register_bot_account(%{name: bot_params["name"], summary: bot_params["summary"]}),
|
||||
bot_params <- Map.put(bot_params, "actor_id", actor.id),
|
||||
{:ok, %Bot{} = bot} <- Actors.create_bot(bot_params) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> put_resp_header("location", bot_path(conn, :show, bot))
|
||||
|> render("show.json", bot: bot)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
bot = Actors.get_bot!(id)
|
||||
render(conn, "show.json", bot: bot)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "bot" => bot_params}) do
|
||||
bot = Actors.get_bot!(id)
|
||||
|
||||
with {:ok, %Bot{} = bot} <- Actors.update_bot(bot, bot_params) do
|
||||
render(conn, "show.json", bot: bot)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
bot = Actors.get_bot!(id)
|
||||
with {:ok, %Bot{}} <- Actors.delete_bot(bot) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -35,6 +35,11 @@ defmodule EventosWeb.EventController do
|
||||
end
|
||||
end
|
||||
|
||||
def search(conn, %{"name" => name}) do
|
||||
events = Events.find_events_by_name(name)
|
||||
render(conn, "index.json", events: events)
|
||||
end
|
||||
|
||||
def show(conn, %{"username" => username, "slug" => slug}) do
|
||||
event = Events.get_event_full_by_name_and_slug!(username, slug)
|
||||
render(conn, "show.json", event: event)
|
||||
|
||||
20
lib/eventos_web/controllers/search_controller.ex
Normal file
20
lib/eventos_web/controllers/search_controller.ex
Normal file
@@ -0,0 +1,20 @@
|
||||
defmodule EventosWeb.SearchController do
|
||||
@moduledoc """
|
||||
Controller for Search
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
alias Eventos.Actors
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
def search(conn, %{"name" => name}) do
|
||||
events = Events.find_events_by_name(name)
|
||||
case Actors.search(name) do # find already saved accounts
|
||||
{:ok, actors} ->
|
||||
render(conn, "search.json", events: events, actors: actors)
|
||||
{:error, err} -> json(conn, err)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user