<commit_before>defmodule OntagCoreWeb.EntryController do
  use OntagCoreWeb, :controller
  alias OntagCore.CMS

  plug OntagCoreWeb.Authentication when action in [:create]
  action_fallback OntagCoreWeb.FallbackController

  def create(conn, params) do
    author = CMS.ensure_author_exists(conn.assigns[:current_user])

    with {:ok, entry} <- CMS.create_entry(author, params) do
      conn
      |> put_status(:created)
      |> json(%{id: entry.id})
    end
  end

  def index(conn, _) do
    entries =
      CMS.list_entries()
      |> Enum.map(fn entry -> %{id: entry.id, title: entry.title} end)

    conn
    |> put_status(:ok)
    |> json(entries)
  end

  def show(conn, %{"id" => id}) do
    with {:ok, entry} <- CMS.get_entry(id) do
      conn
      |> put_status(:ok)
      |> json(%{id: entry.id, title: entry.title})
    end
  end

  def delete(conn, %{"id" => id}) do
    with {:ok, entry} <- CMS.delete_entry(id) do
      conn
      |> put_status(:ok)
      |> json(%{id: entry.id, title: entry.title})
    end
  end
end
<commit_msg>Update the values returned in /entries<commit_after>defmodule OntagCoreWeb.EntryController do
  use OntagCoreWeb, :controller
  alias OntagCore.CMS
  alias OntagCore.Repo

  plug OntagCoreWeb.Authentication when action in [:create]
  action_fallback OntagCoreWeb.FallbackController

  def create(conn, params) do
    author = CMS.ensure_author_exists(conn.assigns[:current_user])

    with {:ok, entry} <- CMS.create_entry(author, params) do
      conn
      |> put_status(:created)
      |> json(%{id: entry.id})
    end
  end

  def index(conn, _) do
    entries =
      CMS.list_entries()
      |> Repo.preload(:medium_post)
      |> Repo.preload(:external_html)
      |> Enum.map(&take/1)

    conn
    |> put_status(:ok)
    |> json(entries)
  end

  def show(conn, %{"id" => id}) do
    with {:ok, entry} <- CMS.get_entry(id) do
      conn
      |> put_status(:ok)
      |> json(%{id: entry.id, title: entry.title})
    end
  end

  def delete(conn, %{"id" => id}) do
    with {:ok, entry} <- CMS.delete_entry(id) do
      conn
      |> put_status(:ok)
      |> json(%{id: entry.id, title: entry.title})
    end
  end

  defp take(entry) do
    base = %{
      id: entry.id,
      title: entry.title,
      entry_type: entry.entry_type
    }

    extra =
      case entry.entry_type do
        "medium_post" ->
          %{medium_post: %{title: entry.medium_post.title,
                           uri: entry.medium_post.uri}}

        "external_html" ->
          %{}
      end

    Map.merge(base, extra)
  end
end

{'fraction_non_alphanumeric': 0.1364696734059098, 'fraction_numerical': 0.00038880248833592535, 'mean_word_length': 2.588563458856346, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2645555', 'n_tokens_mistral': 931, 'n_tokens_neox': 866, 'n_words': 202}