2019-10-06 23:41:18 +00:00
|
|
|
defmodule ClacksWeb.ActivitiesController do
|
|
|
|
use ClacksWeb, :controller
|
2020-04-27 02:57:47 +00:00
|
|
|
alias Clacks.Activity
|
2019-10-06 23:41:18 +00:00
|
|
|
alias ClacksWeb.Router.Helpers, as: Routes
|
|
|
|
alias ClacksWeb.Endpoint
|
|
|
|
|
|
|
|
def get(conn, _params) do
|
|
|
|
ap_id = current_url(conn, %{})
|
|
|
|
|
|
|
|
case Activity.get_by_ap_id(ap_id) do
|
|
|
|
%Activity{local: true, id: id, data: data} ->
|
|
|
|
case conn.assigns[:format] do
|
|
|
|
"activity+json" ->
|
|
|
|
json(conn, data)
|
|
|
|
|
|
|
|
"html" ->
|
|
|
|
redirect(conn, to: Routes.frontend_path(Endpoint, :status, id))
|
|
|
|
end
|
|
|
|
|
|
|
|
_ ->
|
2020-04-23 02:54:46 +00:00
|
|
|
case conn.assigns[:format] do
|
|
|
|
"activity+json" ->
|
|
|
|
conn
|
|
|
|
|> put_status(404)
|
|
|
|
|> json(%{error: "Not Found"})
|
|
|
|
|
|
|
|
"html" ->
|
|
|
|
resp(conn, 404, "Not Found")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_status(conn, %{"id" => status_id}) do
|
|
|
|
case Activity.get(status_id) do
|
|
|
|
%Activity{local: true, data: data} ->
|
|
|
|
json(conn, data)
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
conn
|
|
|
|
|> put_status(404)
|
|
|
|
|> json(%{error: "Not Found"})
|
2019-10-06 23:41:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|