 defmodule AtomTweaksWeb.TweakController do
   use AtomTweaksWeb, :controller
 
-  alias AtomTweaks.Accounts.User
   alias AtomTweaks.Tweaks
   alias AtomTweaks.Tweaks.Tweak
   alias AtomTweaksWeb.NotLoggedInError


  **Not implemented.**
  """
  @spec delete(Plug.Conn.t(), Map.t(), current_user) :: Plug.Conn.t()
  def delete(conn, _params, _current_user) do
    conn
  end

  @doc """
  Displays the edit tweak form.
  """
  @spec edit(Plug.Conn.t(), Map.t(), current_user) :: Plug.Conn.t()
  def edit(conn, params, current_user)

  def edit(conn, _, :guest), do: raise(NotLoggedInError, conn: conn)

  def edit(conn, %{"id" => id}, current_user) do
    tweak =
      Tweak
      |> Repo.get(id)


  require Logger

  @doc """
  Creates a new tweak with the given parameters.
  """
  @spec create(Plug.Conn.t(), Map.t()) :: Plug.Conn.t()
  def create(conn, params)

  def create(conn = %{assigns: %{current_user: nil}}, _), do: raise(NotLoggedInError, conn: conn)

  def create(conn, %{"tweak" => tweak_params}) do
    current_user = conn.assigns.current_user
    params = Map.merge(tweak_params, %{"created_by" => current_user.id})
    changeset = Tweak.changeset(%Tweak{}, params)

