lib/openagents_web/controllers/comment_json.ex

58e6347eeb72 · 546 B

defmodule OpenAgentsWeb.CommentJSON do
  @moduledoc """
  Renders GitHub-compatible issue comment JSON.
  """

  def render("index.json", %{comments: comments}) do
    %{comments: Enum.map(comments, &comment_json/1)}
  end

  def render("show.json", %{comment: comment}) do
    comment_json(comment)
  end

  defp comment_json(comment) do
    %{
      id: comment.id,
      node_id: "IC_#{comment.id}",
      body: comment.body,
      user: comment.user,
      created_at: comment.created_at,
      updated_at: comment.updated_at
    }
  end
end