removing 'properties' from boilerplate
This commit is contained in:
parent
82ab1d1ea5
commit
3a9f00b14e
16 changed files with 16 additions and 2058 deletions
lib/shift73k
|
@ -1,104 +0,0 @@
|
|||
defmodule Shift73k.Properties do
|
||||
@moduledoc """
|
||||
The Properties context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Shift73k.Repo
|
||||
|
||||
alias Shift73k.Properties.Property
|
||||
|
||||
@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{}
|
||||
|> Property.create_changeset(attrs)
|
||||
|> 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
|
|
@ -1,28 +0,0 @@
|
|||
defmodule Shift73k.Properties.Property do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
schema "properties" do
|
||||
field(:description, :string)
|
||||
field(:name, :string)
|
||||
field(:price, :decimal)
|
||||
field(:user_id, :binary_id)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def create_changeset(property, attrs) do
|
||||
property
|
||||
|> cast(attrs, [:name, :price, :description, :user_id])
|
||||
|> validate_required([:name, :price, :description, :user_id])
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(property, attrs) do
|
||||
property
|
||||
|> cast(attrs, [:name, :price, :description])
|
||||
|> validate_required([:name, :price, :description])
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue