@@ -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
|
||||
@@ -39,11 +39,13 @@ defmodule EventosWeb.Router do
|
||||
post "/login", UserSessionController, :sign_in
|
||||
#resources "/groups", GroupController, only: [:index, :show]
|
||||
get "/events", EventController, :index
|
||||
get "/events/search/:name", EventController, :search
|
||||
get "/events/:username/:slug", EventController, :show
|
||||
get "/events/:username/:slug/ics", EventController, :export_to_ics
|
||||
get "/events/:username/:slug/tracks", TrackController, :show_tracks_for_event
|
||||
get "/events/:username/:slug/sessions", SessionController, :show_sessions_for_event
|
||||
resources "/comments", CommentController, only: [:show]
|
||||
get "/bots/:id", BotController, :view
|
||||
|
||||
get "/actors", ActorController, :index
|
||||
get "/actors/search/:name", ActorController, :search
|
||||
@@ -53,6 +55,8 @@ defmodule EventosWeb.Router do
|
||||
resources "/sessions", SessionController, only: [:index, :show]
|
||||
resources "/tracks", TrackController, only: [:index, :show]
|
||||
resources "/addresses", AddressController, only: [:index, :show]
|
||||
|
||||
get "/search/:name", SearchController, :search
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,9 +74,10 @@ defmodule EventosWeb.Router do
|
||||
patch "/events/:username/:slug", EventController, :update
|
||||
put "/events/:username/:slug", EventController, :update
|
||||
delete "/events/:username/:slug", EventController, :delete
|
||||
resources "/comments", CommentController, except: [:new, :edit]
|
||||
resources "/comments", CommentController, except: [:new, :edit, :show]
|
||||
#post "/events/:id/request", EventRequestController, :create_for_event
|
||||
resources "/participant", ParticipantController
|
||||
resources "/bots", BotController, except: [:new, :edit, :show]
|
||||
#resources "/requests", EventRequestController
|
||||
#resources "/groups", GroupController, except: [:index, :show]
|
||||
#post "/groups/:id/request", GroupRequestController, :create_for_group
|
||||
|
||||
@@ -9,6 +9,7 @@ defmodule EventosWeb.ActivityPub.ActorView do
|
||||
alias Eventos.Service.ActivityPub
|
||||
alias Eventos.Service.ActivityPub.Transmogrifier
|
||||
alias Eventos.Service.ActivityPub.Utils
|
||||
alias Eventos.Activity
|
||||
import Ecto.Query
|
||||
|
||||
def render("actor.json", %{actor: actor}) do
|
||||
@@ -123,10 +124,10 @@ defmodule EventosWeb.ActivityPub.ActorView do
|
||||
end
|
||||
end
|
||||
|
||||
def render("activity.json", %{activity: activity}) do
|
||||
def render("activity.json", %{activity: %Activity{local: local} = activity}) do
|
||||
%{
|
||||
"id" => activity.data.url <> "/activity",
|
||||
"type" => "Create",
|
||||
"type" => if local do "Create" else "Announce" end,
|
||||
"actor" => activity.data.organizer_actor.url,
|
||||
"published" => Timex.now(),
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
defmodule EventosWeb.ActivityPub.ObjectView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.ActivityPub.ObjectView
|
||||
alias Eventos.Service.ActivityPub.Transmogrifier
|
||||
@base %{
|
||||
"@context" => [
|
||||
@@ -22,7 +23,7 @@ defmodule EventosWeb.ActivityPub.ObjectView do
|
||||
"type" => "Event",
|
||||
"id" => event.url,
|
||||
"name" => event.title,
|
||||
"category" => %{"title" => event.category.title},
|
||||
"category" => render_one(event.category, ObjectView, "category.json", as: :category),
|
||||
"content" => event.description,
|
||||
"mediaType" => "text/markdown",
|
||||
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
|
||||
@@ -32,6 +33,10 @@ defmodule EventosWeb.ActivityPub.ObjectView do
|
||||
end
|
||||
|
||||
def render("category.json", %{category: category}) do
|
||||
category
|
||||
%{"title" => category.title}
|
||||
end
|
||||
|
||||
def render("category.json", %{category: nil}) do
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,6 +23,7 @@ defmodule EventosWeb.ActorView do
|
||||
domain: actor.domain,
|
||||
display_name: actor.name,
|
||||
description: actor.summary,
|
||||
type: actor.type,
|
||||
# public_key: actor.public_key,
|
||||
suspended: actor.suspended,
|
||||
url: actor.url,
|
||||
@@ -35,6 +36,7 @@ defmodule EventosWeb.ActorView do
|
||||
domain: actor.domain,
|
||||
display_name: actor.name,
|
||||
description: actor.summary,
|
||||
type: actor.type,
|
||||
# public_key: actor.public_key,
|
||||
suspended: actor.suspended,
|
||||
url: actor.url,
|
||||
|
||||
18
lib/eventos_web/views/bot_view.ex
Normal file
18
lib/eventos_web/views/bot_view.ex
Normal file
@@ -0,0 +1,18 @@
|
||||
defmodule EventosWeb.BotView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.BotView
|
||||
|
||||
def render("index.json", %{bots: bots}) do
|
||||
%{data: render_many(bots, BotView, "bot.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{bot: bot}) do
|
||||
%{data: render_one(bot, BotView, "bot.json")}
|
||||
end
|
||||
|
||||
def render("bot.json", %{bot: bot}) do
|
||||
%{id: bot.id,
|
||||
source: bot.source,
|
||||
type: bot.type}
|
||||
end
|
||||
end
|
||||
@@ -34,6 +34,7 @@ defmodule EventosWeb.EventView do
|
||||
organizer: %{
|
||||
username: event.organizer_actor.preferred_username
|
||||
},
|
||||
type: "Event",
|
||||
}
|
||||
end
|
||||
|
||||
@@ -46,6 +47,7 @@ defmodule EventosWeb.EventView do
|
||||
organizer: render_one(event.organizer_actor, ActorView, "acccount_basic.json"),
|
||||
participants: render_many(event.participants, ActorView, "show_basic.json"),
|
||||
address: render_one(event.address, AddressView, "address.json"),
|
||||
type: "Event",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
16
lib/eventos_web/views/search_view.ex
Normal file
16
lib/eventos_web/views/search_view.ex
Normal file
@@ -0,0 +1,16 @@
|
||||
defmodule EventosWeb.SearchView do
|
||||
@moduledoc """
|
||||
View for Events
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.{EventView, ActorView, GroupView, AddressView}
|
||||
|
||||
def render("search.json", %{events: events, actors: actors}) do
|
||||
%{
|
||||
data: %{
|
||||
events: render_many(events, EventView, "event_simple.json"),
|
||||
actors: render_many(actors, ActorView, "acccount_basic.json"),
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user