clacks/lib/clacks_web/controllers/activities_controller.ex

31 lines
744 B
Elixir
Raw Normal View History

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, %{"id" => id}) do
case Activity.get(id) do
%Activity{local: true, data: data} ->
2019-10-06 23:41:18 +00:00
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
2019-10-06 23:41:18 +00:00
end