philomena/lib/philomena/versions.ex
2019-08-28 18:41:03 -04:00

104 lines
1.8 KiB
Elixir

defmodule Philomena.Versions do
@moduledoc """
The Versions context.
"""
import Ecto.Query, warn: false
alias Philomena.Repo
alias Philomena.Versions.Version
@doc """
Returns the list of versions.
## Examples
iex> list_versions()
[%Version{}, ...]
"""
def list_versions do
Repo.all(Version)
end
@doc """
Gets a single version.
Raises `Ecto.NoResultsError` if the Version does not exist.
## Examples
iex> get_version!(123)
%Version{}
iex> get_version!(456)
** (Ecto.NoResultsError)
"""
def get_version!(id), do: Repo.get!(Version, id)
@doc """
Creates a version.
## Examples
iex> create_version(%{field: value})
{:ok, %Version{}}
iex> create_version(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_version(attrs \\ %{}) do
%Version{}
|> Version.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a version.
## Examples
iex> update_version(version, %{field: new_value})
{:ok, %Version{}}
iex> update_version(version, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_version(%Version{} = version, attrs) do
version
|> Version.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Version.
## Examples
iex> delete_version(version)
{:ok, %Version{}}
iex> delete_version(version)
{:error, %Ecto.Changeset{}}
"""
def delete_version(%Version{} = version) do
Repo.delete(version)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking version changes.
## Examples
iex> change_version(version)
%Ecto.Changeset{source: %Version{}}
"""
def change_version(%Version{} = version) do
Version.changeset(version, %{})
end
end