context: image_features, image_intensities, image_subscriptions

This commit is contained in:
Liam P. White 2019-08-28 13:19:27 -04:00
parent 8473541e3e
commit ce54176940
5 changed files with 519 additions and 0 deletions

View file

@ -103,4 +103,292 @@ defmodule Philomena.Images do
def change_image(%Image{} = image) do
Image.changeset(image, %{})
end
alias Philomena.Images.Features
@doc """
Returns the list of image_features.
## Examples
iex> list_image_features()
[%Features{}, ...]
"""
def list_image_features do
Repo.all(Features)
end
@doc """
Gets a single features.
Raises `Ecto.NoResultsError` if the Features does not exist.
## Examples
iex> get_features!(123)
%Features{}
iex> get_features!(456)
** (Ecto.NoResultsError)
"""
def get_features!(id), do: Repo.get!(Features, id)
@doc """
Creates a features.
## Examples
iex> create_features(%{field: value})
{:ok, %Features{}}
iex> create_features(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_features(attrs \\ %{}) do
%Features{}
|> Features.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a features.
## Examples
iex> update_features(features, %{field: new_value})
{:ok, %Features{}}
iex> update_features(features, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_features(%Features{} = features, attrs) do
features
|> Features.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Features.
## Examples
iex> delete_features(features)
{:ok, %Features{}}
iex> delete_features(features)
{:error, %Ecto.Changeset{}}
"""
def delete_features(%Features{} = features) do
Repo.delete(features)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking features changes.
## Examples
iex> change_features(features)
%Ecto.Changeset{source: %Features{}}
"""
def change_features(%Features{} = features) do
Features.changeset(features, %{})
end
alias Philomena.Images.Intensities
@doc """
Returns the list of image_intensities.
## Examples
iex> list_image_intensities()
[%Intensities{}, ...]
"""
def list_image_intensities do
Repo.all(Intensities)
end
@doc """
Gets a single intensities.
Raises `Ecto.NoResultsError` if the Intensities does not exist.
## Examples
iex> get_intensities!(123)
%Intensities{}
iex> get_intensities!(456)
** (Ecto.NoResultsError)
"""
def get_intensities!(id), do: Repo.get!(Intensities, id)
@doc """
Creates a intensities.
## Examples
iex> create_intensities(%{field: value})
{:ok, %Intensities{}}
iex> create_intensities(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_intensities(attrs \\ %{}) do
%Intensities{}
|> Intensities.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a intensities.
## Examples
iex> update_intensities(intensities, %{field: new_value})
{:ok, %Intensities{}}
iex> update_intensities(intensities, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_intensities(%Intensities{} = intensities, attrs) do
intensities
|> Intensities.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Intensities.
## Examples
iex> delete_intensities(intensities)
{:ok, %Intensities{}}
iex> delete_intensities(intensities)
{:error, %Ecto.Changeset{}}
"""
def delete_intensities(%Intensities{} = intensities) do
Repo.delete(intensities)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking intensities changes.
## Examples
iex> change_intensities(intensities)
%Ecto.Changeset{source: %Intensities{}}
"""
def change_intensities(%Intensities{} = intensities) do
Intensities.changeset(intensities, %{})
end
alias Philomena.Images.Subscription
@doc """
Returns the list of image_subscriptions.
## Examples
iex> list_image_subscriptions()
[%Subscription{}, ...]
"""
def list_image_subscriptions do
Repo.all(Subscription)
end
@doc """
Gets a single subscription.
Raises `Ecto.NoResultsError` if the Subscription does not exist.
## Examples
iex> get_subscription!(123)
%Subscription{}
iex> get_subscription!(456)
** (Ecto.NoResultsError)
"""
def get_subscription!(id), do: Repo.get!(Subscription, id)
@doc """
Creates a subscription.
## Examples
iex> create_subscription(%{field: value})
{:ok, %Subscription{}}
iex> create_subscription(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_subscription(attrs \\ %{}) do
%Subscription{}
|> Subscription.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a subscription.
## Examples
iex> update_subscription(subscription, %{field: new_value})
{:ok, %Subscription{}}
iex> update_subscription(subscription, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_subscription(%Subscription{} = subscription, attrs) do
subscription
|> Subscription.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Subscription.
## Examples
iex> delete_subscription(subscription)
{:ok, %Subscription{}}
iex> delete_subscription(subscription)
{:error, %Ecto.Changeset{}}
"""
def delete_subscription(%Subscription{} = subscription) do
Repo.delete(subscription)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking subscription changes.
## Examples
iex> change_subscription(subscription)
%Ecto.Changeset{source: %Subscription{}}
"""
def change_subscription(%Subscription{} = subscription) do
Subscription.changeset(subscription, %{})
end
end

View file

@ -0,0 +1,20 @@
defmodule Philomena.Images.Features do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
schema "image_features" do
belongs_to :image, Philomena.Images.Image
belongs_to :user, Philomena.Users.User
timestamps(inserted_at: :created_at)
end
@doc false
def changeset(features, attrs) do
features
|> cast(attrs, [])
|> validate_required([])
end
end

View file

@ -0,0 +1,22 @@
defmodule Philomena.Images.Intensities do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
schema "image_intensities" do
belongs_to :image, Philomena.Images.Image, primary_key: true
field :nw, :float
field :ne, :float
field :sw, :float
field :se, :float
end
@doc false
def changeset(intensities, attrs) do
intensities
|> cast(attrs, [])
|> validate_required([])
end
end

View file

@ -0,0 +1,18 @@
defmodule Philomena.Images.Subscription do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
schema "image_subscriptions" do
belongs_to :image, Philomena.Images.Image, primary_key: true
belongs_to :user, Philomena.Users.User, primary_key: true
end
@doc false
def changeset(subscription, attrs) do
subscription
|> cast(attrs, [])
|> validate_required([])
end
end

View file

@ -59,4 +59,175 @@ defmodule Philomena.ImagesTest do
assert %Ecto.Changeset{} = Images.change_image(image)
end
end
describe "image_features" do
alias Philomena.Images.Features
@valid_attrs %{}
@update_attrs %{}
@invalid_attrs %{}
def features_fixture(attrs \\ %{}) do
{:ok, features} =
attrs
|> Enum.into(@valid_attrs)
|> Images.create_features()
features
end
test "list_image_features/0 returns all image_features" do
features = features_fixture()
assert Images.list_image_features() == [features]
end
test "get_features!/1 returns the features with given id" do
features = features_fixture()
assert Images.get_features!(features.id) == features
end
test "create_features/1 with valid data creates a features" do
assert {:ok, %Features{} = features} = Images.create_features(@valid_attrs)
end
test "create_features/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Images.create_features(@invalid_attrs)
end
test "update_features/2 with valid data updates the features" do
features = features_fixture()
assert {:ok, %Features{} = features} = Images.update_features(features, @update_attrs)
end
test "update_features/2 with invalid data returns error changeset" do
features = features_fixture()
assert {:error, %Ecto.Changeset{}} = Images.update_features(features, @invalid_attrs)
assert features == Images.get_features!(features.id)
end
test "delete_features/1 deletes the features" do
features = features_fixture()
assert {:ok, %Features{}} = Images.delete_features(features)
assert_raise Ecto.NoResultsError, fn -> Images.get_features!(features.id) end
end
test "change_features/1 returns a features changeset" do
features = features_fixture()
assert %Ecto.Changeset{} = Images.change_features(features)
end
end
describe "image_intensities" do
alias Philomena.Images.Intensities
@valid_attrs %{}
@update_attrs %{}
@invalid_attrs %{}
def intensities_fixture(attrs \\ %{}) do
{:ok, intensities} =
attrs
|> Enum.into(@valid_attrs)
|> Images.create_intensities()
intensities
end
test "list_image_intensities/0 returns all image_intensities" do
intensities = intensities_fixture()
assert Images.list_image_intensities() == [intensities]
end
test "get_intensities!/1 returns the intensities with given id" do
intensities = intensities_fixture()
assert Images.get_intensities!(intensities.id) == intensities
end
test "create_intensities/1 with valid data creates a intensities" do
assert {:ok, %Intensities{} = intensities} = Images.create_intensities(@valid_attrs)
end
test "create_intensities/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Images.create_intensities(@invalid_attrs)
end
test "update_intensities/2 with valid data updates the intensities" do
intensities = intensities_fixture()
assert {:ok, %Intensities{} = intensities} = Images.update_intensities(intensities, @update_attrs)
end
test "update_intensities/2 with invalid data returns error changeset" do
intensities = intensities_fixture()
assert {:error, %Ecto.Changeset{}} = Images.update_intensities(intensities, @invalid_attrs)
assert intensities == Images.get_intensities!(intensities.id)
end
test "delete_intensities/1 deletes the intensities" do
intensities = intensities_fixture()
assert {:ok, %Intensities{}} = Images.delete_intensities(intensities)
assert_raise Ecto.NoResultsError, fn -> Images.get_intensities!(intensities.id) end
end
test "change_intensities/1 returns a intensities changeset" do
intensities = intensities_fixture()
assert %Ecto.Changeset{} = Images.change_intensities(intensities)
end
end
describe "image_subscriptions" do
alias Philomena.Images.Subscription
@valid_attrs %{}
@update_attrs %{}
@invalid_attrs %{}
def subscription_fixture(attrs \\ %{}) do
{:ok, subscription} =
attrs
|> Enum.into(@valid_attrs)
|> Images.create_subscription()
subscription
end
test "list_image_subscriptions/0 returns all image_subscriptions" do
subscription = subscription_fixture()
assert Images.list_image_subscriptions() == [subscription]
end
test "get_subscription!/1 returns the subscription with given id" do
subscription = subscription_fixture()
assert Images.get_subscription!(subscription.id) == subscription
end
test "create_subscription/1 with valid data creates a subscription" do
assert {:ok, %Subscription{} = subscription} = Images.create_subscription(@valid_attrs)
end
test "create_subscription/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Images.create_subscription(@invalid_attrs)
end
test "update_subscription/2 with valid data updates the subscription" do
subscription = subscription_fixture()
assert {:ok, %Subscription{} = subscription} = Images.update_subscription(subscription, @update_attrs)
end
test "update_subscription/2 with invalid data returns error changeset" do
subscription = subscription_fixture()
assert {:error, %Ecto.Changeset{}} = Images.update_subscription(subscription, @invalid_attrs)
assert subscription == Images.get_subscription!(subscription.id)
end
test "delete_subscription/1 deletes the subscription" do
subscription = subscription_fixture()
assert {:ok, %Subscription{}} = Images.delete_subscription(subscription)
assert_raise Ecto.NoResultsError, fn -> Images.get_subscription!(subscription.id) end
end
test "change_subscription/1 returns a subscription changeset" do
subscription = subscription_fixture()
assert %Ecto.Changeset{} = Images.change_subscription(subscription)
end
end
end