shift73k/lib/bones73k/properties.ex

105 lines
1.9 KiB
Elixir
Raw Normal View History

2021-02-24 07:49:39 -05:00
defmodule Bones73k.Properties do
2020-09-14 12:22:25 -04:00
@moduledoc """
The Properties context.
"""
import Ecto.Query, warn: false
2021-02-24 07:49:39 -05:00
alias Bones73k.Repo
2020-09-14 12:22:25 -04:00
2021-02-24 07:49:39 -05:00
alias Bones73k.Properties.Property
2020-09-14 12:22:25 -04:00
@doc """
Returns the list of properties.
## Examples
iex> list_properties()
[%Property{}, ...]
"""
def list_properties do
Repo.all(Property)
end
@doc """
Gets a single property.
Raises `Ecto.NoResultsError` if the Property does not exist.
## Examples
iex> get_property!(123)
%Property{}
iex> get_property!(456)
** (Ecto.NoResultsError)
"""
def get_property!(id), do: Repo.get!(Property, id)
@doc """
Creates a property.
## Examples
iex> create_property(%{field: value})
{:ok, %Property{}}
iex> create_property(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_property(attrs \\ %{}) do
%Property{}
2020-09-14 19:45:56 -04:00
|> Property.create_changeset(attrs)
2020-09-14 12:22:25 -04:00
|> Repo.insert()
end
@doc """
Updates a property.
## Examples
iex> update_property(property, %{field: new_value})
{:ok, %Property{}}
iex> update_property(property, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_property(%Property{} = property, attrs) do
property
|> Property.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a property.
## Examples
iex> delete_property(property)
{:ok, %Property{}}
iex> delete_property(property)
{:error, %Ecto.Changeset{}}
"""
def delete_property(%Property{} = property) do
Repo.delete(property)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking property changes.
## Examples
iex> change_property(property)
%Ecto.Changeset{data: %Property{}}
"""
def change_property(%Property{} = property, attrs \\ %{}) do
Property.changeset(property, attrs)
end
end