defmodule SomethingErlang.Forums do @moduledoc """ The Forums context. """ import Ecto.Query, warn: false alias SomethingErlang.Repo alias SomethingErlang.Forums.Thread @doc """ Returns the list of threads. ## Examples iex> list_threads() [%Thread{}, ...] """ def list_threads do Repo.all(Thread) end @doc """ Gets a single thread. Raises `Ecto.NoResultsError` if the Thread does not exist. ## Examples iex> get_thread!(123) %Thread{} iex> get_thread!(456) ** (Ecto.NoResultsError) """ def get_thread!(id), # Repo.get!(Thread, id) do: %Thread{id: id, thread_id: id, title: "foo"} @doc """ Creates a thread. ## Examples iex> create_thread(%{field: value}) {:ok, %Thread{}} iex> create_thread(%{field: bad_value}) {:error, %Ecto.Changeset{}} """ def create_thread(attrs \\ %{}) do %Thread{} |> Thread.changeset(attrs) |> Repo.insert() end @doc """ Updates a thread. ## Examples iex> update_thread(thread, %{field: new_value}) {:ok, %Thread{}} iex> update_thread(thread, %{field: bad_value}) {:error, %Ecto.Changeset{}} """ def update_thread(%Thread{} = thread, attrs) do thread |> Thread.changeset(attrs) |> Repo.update() end @doc """ Deletes a thread. ## Examples iex> delete_thread(thread) {:ok, %Thread{}} iex> delete_thread(thread) {:error, %Ecto.Changeset{}} """ def delete_thread(%Thread{} = thread) do Repo.delete(thread) end @doc """ Returns an `%Ecto.Changeset{}` for tracking thread changes. ## Examples iex> change_thread(thread) %Ecto.Changeset{data: %Thread{}} """ def change_thread(%Thread{} = thread, attrs \\ %{}) do Thread.changeset(thread, attrs) end end