Editable landing page.
This commit is contained in:
104
lib/runosaari/pages.ex
Normal file
104
lib/runosaari/pages.ex
Normal file
@@ -0,0 +1,104 @@
|
||||
defmodule Runosaari.Pages do
|
||||
@moduledoc """
|
||||
The Pages context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Runosaari.Repo
|
||||
|
||||
alias Runosaari.Pages.Index
|
||||
|
||||
@doc """
|
||||
Returns the list of index_paragraphs.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_index_paragraphs()
|
||||
[%Index{}, ...]
|
||||
|
||||
"""
|
||||
def list_index_paragraphs do
|
||||
Repo.all(Index)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single index.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Index does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_index!(123)
|
||||
%Index{}
|
||||
|
||||
iex> get_index!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_index!(id), do: Repo.get!(Index, id)
|
||||
|
||||
@doc """
|
||||
Creates a index.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_index(%{field: value})
|
||||
{:ok, %Index{}}
|
||||
|
||||
iex> create_index(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_index(attrs \\ %{}) do
|
||||
%Index{}
|
||||
|> Index.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a index.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_index(index, %{field: new_value})
|
||||
{:ok, %Index{}}
|
||||
|
||||
iex> update_index(index, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_index(%Index{} = index, attrs) do
|
||||
index
|
||||
|> Index.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a index.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_index(index)
|
||||
{:ok, %Index{}}
|
||||
|
||||
iex> delete_index(index)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_index(%Index{} = index) do
|
||||
Repo.delete(index)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking index changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_index(index)
|
||||
%Ecto.Changeset{data: %Index{}}
|
||||
|
||||
"""
|
||||
def change_index(%Index{} = index, attrs \\ %{}) do
|
||||
Index.changeset(index, attrs)
|
||||
end
|
||||
end
|
||||
18
lib/runosaari/pages/index.ex
Normal file
18
lib/runosaari/pages/index.ex
Normal file
@@ -0,0 +1,18 @@
|
||||
defmodule Runosaari.Pages.Index do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "index_paragraphs" do
|
||||
field :content, :string
|
||||
field :seqnum, :integer, default: 999
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(index, attrs) do
|
||||
index
|
||||
|> cast(attrs, [:content, :seqnum])
|
||||
|> validate_required([:content, :seqnum])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user