clacks/lib/clacks_web/controllers/activities_controller.ex

31 lines
744 B
Elixir

defmodule ClacksWeb.ActivitiesController do
use ClacksWeb, :controller
alias Clacks.Activity
alias ClacksWeb.Router.Helpers, as: Routes
alias ClacksWeb.Endpoint
def get(conn, %{"id" => id}) do
case Activity.get(id) do
%Activity{local: true, data: data} ->
case conn.assigns[:format] do
"activity+json" ->
json(conn, data)
"html" ->
redirect(conn, to: Routes.frontend_path(Endpoint, :status, id))
end
_ ->
case conn.assigns[:format] do
"activity+json" ->
conn
|> put_status(404)
|> json(%{error: "Not Found"})
"html" ->
resp(conn, 404, "Not Found")
end
end
end
end