   plug(:check_if_site_exists when action in [:check])
   plug(:check_rate_ip when action in [:check])
   plug(:check_rate_url_host when action in [:check])
+  plug(:validate_id when action in [:status])
 
   def check(%Plug.Conn{assigns: %{input_url: proper_url}} = conn, _params) do
     {:ok, id} = Sites.add_site(proper_url)


  defp handle_results({id, site}, conn, _url) do
    case site.status do
      "queue" ->
        redirect(conn,
          to: Routes.site_path(conn, :status, conn.assigns.locale, id: id, site: site)
        )

      "processing" ->
        redirect(conn,
          to: Routes.site_path(conn, :status, conn.assigns.locale, id: id, site: site)
        )

  end

  def status(conn, %{"id" => id}) do
    id
    |> Sites.get_site()
    |> handle_status(id, conn)
  end

  defp handle_status(%Sites.Site{status: "done"} = site, _id, conn) do
    redirect(conn,
      to: Routes.site_path(conn, :results, conn.assigns.locale, url: site.input_url)
    )
  end

  defp handle_status(site, id, conn) do
    case site.status do
      x when x in ["queue", "processing"] ->
        render(conn, "status.html", id: id, site: site, page_title: gettext("Status"))

      x when x in ["failed", "done"] ->
        redirect(conn,
          to: Routes.site_path(conn, :results, conn.assigns.locale, url: site.input_url)
        )
