clacks/lib/clacks_web/controllers/objects_controller.ex

22 lines
514 B
Elixir
Raw Normal View History

2019-09-29 01:57:11 +00:00
defmodule ClacksWeb.ObjectsController do
use ClacksWeb, :controller
alias Clacks.{Repo, Object, ActivityPub}
import Ecto.Query
def get(conn, %{"id" => id}) do
object_id = current_url(conn)
query = from(o in Object, where: fragment("?->>'id'", o.data) == ^object_id)
case Repo.one(query) do
nil ->
conn
|> put_status(404)
object ->
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(object.data)
end
end
end