From 897ed77709bff70b98ecf9083c367477aaa6c27e Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 16 Nov 2019 18:42:41 -0500 Subject: [PATCH] split image context --- .iex.exs | 2 +- config/dev.exs | 1 + lib/philomena/badges/award.ex | 9 +- lib/philomena/bans/fingerprint.ex | 4 +- lib/philomena/bans/subnet.ex | 4 +- lib/philomena/bans/user.ex | 6 +- lib/philomena/channels/channel.ex | 4 +- lib/philomena/channels/subscription.ex | 7 +- lib/philomena/comments/comment.ex | 9 +- lib/philomena/commissions/commission.ex | 7 +- lib/philomena/commissions/item.ex | 7 +- lib/philomena/conversations/conversation.ex | 6 +- lib/philomena/conversations/message.ex | 7 +- lib/philomena/dnp_entries/dnp_entry.ex | 9 +- lib/philomena/donations/donation.ex | 4 +- .../duplicate_reports/duplicate_report.ex | 11 +- lib/philomena/forums/forum.ex | 7 +- lib/philomena/forums/subscription.ex | 7 +- lib/philomena/galleries/gallery.ex | 7 +- lib/philomena/galleries/interaction.ex | 7 +- lib/philomena/galleries/subscription.ex | 7 +- lib/philomena/image_faves.ex | 104 +++++ lib/philomena/image_faves/image_fave.ex | 22 + lib/philomena/image_features.ex | 104 +++++ lib/philomena/image_features/image_feature.ex | 23 ++ lib/philomena/image_hides.ex | 104 +++++ lib/philomena/image_hides/image_hide.ex | 22 + lib/philomena/image_intensities.ex | 104 +++++ .../image_intensity.ex} | 10 +- lib/philomena/image_votes.ex | 104 +++++ .../vote.ex => image_votes/image_vote.ex} | 13 +- lib/philomena/images.ex | 384 ------------------ lib/philomena/images/fave.ex | 19 - lib/philomena/images/feature.ex | 20 - lib/philomena/images/hide.ex | 19 - lib/philomena/images/image.ex | 23 +- lib/philomena/images/subscription.ex | 7 +- lib/philomena/images/tagging.ex | 7 +- lib/philomena/mod_notes/mod_note.ex | 4 +- .../notifications/unread_notification.ex | 7 +- lib/philomena/poll_options/poll_option.ex | 4 +- lib/philomena/poll_votes/poll_vote.ex | 7 +- lib/philomena/polls/poll.ex | 7 +- lib/philomena/posts/post.ex | 9 +- lib/philomena/reports/report.ex | 6 +- lib/philomena/site_notices/site_notice.ex | 4 +- lib/philomena/source_changes.ex | 104 +++++ .../source_change.ex | 2 +- lib/philomena/tag_changes.ex | 104 +++++ .../{images => tag_changes}/tag_change.ex | 2 +- lib/philomena/tags/implication.ex | 6 +- lib/philomena/tags/tag.ex | 10 +- lib/philomena/topics/topic.ex | 17 +- .../user_fingerprints/user_fingerprint.ex | 4 +- lib/philomena/user_ips/user_ip.ex | 4 +- lib/philomena/user_links/user_link.ex | 11 +- .../user_name_changes/user_name_change.ex | 4 +- .../user_statistics/user_statistic.ex | 4 +- .../user_whitelists/user_whitelist.ex | 4 + lib/philomena/users/role.ex | 7 +- lib/philomena/users/user.ex | 23 +- mix.exs | 2 +- mix.lock | 2 +- test/philomena/image_faves_test.exs | 62 +++ test/philomena/image_features_test.exs | 62 +++ test/philomena/image_hides_test.exs | 62 +++ test/philomena/image_intensities_test.exs | 62 +++ test/philomena/image_votes_test.exs | 62 +++ test/philomena/source_changes_test.exs | 62 +++ test/philomena/tag_changes_test.exs | 62 +++ 70 files changed, 1462 insertions(+), 551 deletions(-) create mode 100644 lib/philomena/image_faves.ex create mode 100644 lib/philomena/image_faves/image_fave.ex create mode 100644 lib/philomena/image_features.ex create mode 100644 lib/philomena/image_features/image_feature.ex create mode 100644 lib/philomena/image_hides.ex create mode 100644 lib/philomena/image_hides/image_hide.ex create mode 100644 lib/philomena/image_intensities.ex rename lib/philomena/{images/intensities.ex => image_intensities/image_intensity.ex} (57%) create mode 100644 lib/philomena/image_votes.ex rename lib/philomena/{images/vote.ex => image_votes/image_vote.ex} (50%) delete mode 100644 lib/philomena/images/fave.ex delete mode 100644 lib/philomena/images/feature.ex delete mode 100644 lib/philomena/images/hide.ex create mode 100644 lib/philomena/source_changes.ex rename lib/philomena/{images => source_changes}/source_change.ex (91%) create mode 100644 lib/philomena/tag_changes.ex rename lib/philomena/{images => tag_changes}/tag_change.ex (93%) create mode 100644 test/philomena/image_faves_test.exs create mode 100644 test/philomena/image_features_test.exs create mode 100644 test/philomena/image_hides_test.exs create mode 100644 test/philomena/image_intensities_test.exs create mode 100644 test/philomena/image_votes_test.exs create mode 100644 test/philomena/source_changes_test.exs create mode 100644 test/philomena/tag_changes_test.exs diff --git a/.iex.exs b/.iex.exs index e8c7de4a..41b58720 100644 --- a/.iex.exs +++ b/.iex.exs @@ -1,3 +1,3 @@ alias Philomena.{Repo, Comments.Comment, Posts.Post, Images.Image, Tags.Tag, Users.User} import Ecto.Query -import Ecto.Changeset \ No newline at end of file +import Ecto.Changeset diff --git a/config/dev.exs b/config/dev.exs index a1c44c87..a7bb8b41 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -61,6 +61,7 @@ config :philomena, PhilomenaWeb.Endpoint, # Do not include metadata nor timestamps in development logs config :logger, :console, format: "[$level] $message\n" +config :logger, compile_time_purge_matching: [[application: :remote_ip]] # Set up mailer config :philomena, PhilomenaWeb.Mailer, diff --git a/lib/philomena/badges/award.ex b/lib/philomena/badges/award.ex index 204fe894..a71bce2f 100644 --- a/lib/philomena/badges/award.ex +++ b/lib/philomena/badges/award.ex @@ -2,10 +2,13 @@ defmodule Philomena.Badges.Award do use Ecto.Schema import Ecto.Changeset + alias Philomena.Badges.Badge + alias Philomena.Users.User + schema "badge_awards" do - belongs_to :user, Philomena.Users.User - belongs_to :awarded_by, Philomena.Users.User - belongs_to :badge, Philomena.Badges.Badge + belongs_to :user, User + belongs_to :awarded_by, User + belongs_to :badge, Badge field :label, :string field :awarded_on, :naive_datetime diff --git a/lib/philomena/bans/fingerprint.ex b/lib/philomena/bans/fingerprint.ex index a76cf137..8002a987 100644 --- a/lib/philomena/bans/fingerprint.ex +++ b/lib/philomena/bans/fingerprint.ex @@ -2,8 +2,10 @@ defmodule Philomena.Bans.Fingerprint do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "fingerprint_bans" do - belongs_to :banning_user, Philomena.Users.User + belongs_to :banning_user, User field :reason, :string field :note, :string diff --git a/lib/philomena/bans/subnet.ex b/lib/philomena/bans/subnet.ex index 7add4880..9c7ef974 100644 --- a/lib/philomena/bans/subnet.ex +++ b/lib/philomena/bans/subnet.ex @@ -2,8 +2,10 @@ defmodule Philomena.Bans.Subnet do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "subnet_bans" do - belongs_to :banning_user, Philomena.Users.User + belongs_to :banning_user, User field :reason, :string field :note, :string diff --git a/lib/philomena/bans/user.ex b/lib/philomena/bans/user.ex index cd72cd20..53a3d6df 100644 --- a/lib/philomena/bans/user.ex +++ b/lib/philomena/bans/user.ex @@ -2,9 +2,11 @@ defmodule Philomena.Bans.User do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_bans" do - belongs_to :user, Philomena.Users.User - belongs_to :banning_user, Philomena.Users.User + belongs_to :user, User + belongs_to :banning_user, User field :reason, :string field :note, :string diff --git a/lib/philomena/channels/channel.ex b/lib/philomena/channels/channel.ex index 6ce5b3c8..1156c095 100644 --- a/lib/philomena/channels/channel.ex +++ b/lib/philomena/channels/channel.ex @@ -2,8 +2,10 @@ defmodule Philomena.Channels.Channel do use Ecto.Schema import Ecto.Changeset + alias Philomena.Tags.Tag + schema "channels" do - belongs_to :associated_artist_tag, Philomena.Tags.Tag + belongs_to :associated_artist_tag, Tag # fixme: rails STI field :type, :string diff --git a/lib/philomena/channels/subscription.ex b/lib/philomena/channels/subscription.ex index 9c4b57e9..da05d2c3 100644 --- a/lib/philomena/channels/subscription.ex +++ b/lib/philomena/channels/subscription.ex @@ -2,11 +2,14 @@ defmodule Philomena.Channels.Subscription do use Ecto.Schema import Ecto.Changeset + alias Philomena.Channels.Channel + alias Philomena.Users.User + @primary_key false schema "channel_subscriptions" do - belongs_to :channel, Philomena.Channels.Channel, primary_key: true - belongs_to :user, Philomena.Users.User, primary_key: true + belongs_to :channel, Channel, primary_key: true + belongs_to :user, User, primary_key: true end @doc false diff --git a/lib/philomena/comments/comment.ex b/lib/philomena/comments/comment.ex index e4398de6..21d731ac 100644 --- a/lib/philomena/comments/comment.ex +++ b/lib/philomena/comments/comment.ex @@ -7,10 +7,13 @@ defmodule Philomena.Comments.Comment do index_name: "comments", doc_type: "comment" + alias Philomena.Images.Image + alias Philomena.Users.User + schema "comments" do - belongs_to :user, Philomena.Users.User - belongs_to :image, Philomena.Images.Image - belongs_to :deleted_by, Philomena.Users.User + belongs_to :user, User + belongs_to :image, Image + belongs_to :deleted_by, User field :body, :string field :ip, EctoNetwork.INET diff --git a/lib/philomena/commissions/commission.ex b/lib/philomena/commissions/commission.ex index ba419e97..80eb5549 100644 --- a/lib/philomena/commissions/commission.ex +++ b/lib/philomena/commissions/commission.ex @@ -2,9 +2,12 @@ defmodule Philomena.Commissions.Commission do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Users.User + schema "commissions" do - belongs_to :user, Philomena.Users.User - belongs_to :sheet_image, Philomena.Images.Image + belongs_to :user, User + belongs_to :sheet_image, Image field :open, :boolean field :categories, {:array, :string}, default: [] diff --git a/lib/philomena/commissions/item.ex b/lib/philomena/commissions/item.ex index f7ce5de2..a0863eed 100644 --- a/lib/philomena/commissions/item.ex +++ b/lib/philomena/commissions/item.ex @@ -2,9 +2,12 @@ defmodule Philomena.Commissions.Item do use Ecto.Schema import Ecto.Changeset + alias Philomena.Commissions.Commission + alias Philomena.Images.Image + schema "commission_items" do - belongs_to :commission, Philomena.Commissions.Commission - belongs_to :example_image, Philomena.Images.Image + belongs_to :commission, Commission + belongs_to :example_image, Image field :item_type, :string field :description, :string diff --git a/lib/philomena/conversations/conversation.ex b/lib/philomena/conversations/conversation.ex index 70060db8..5e82630b 100644 --- a/lib/philomena/conversations/conversation.ex +++ b/lib/philomena/conversations/conversation.ex @@ -2,11 +2,13 @@ defmodule Philomena.Conversations.Conversation do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + @derive {Phoenix.Param, key: :slug} schema "conversations" do - belongs_to :from, Philomena.Users.User - belongs_to :to, Philomena.Users.User + belongs_to :from, User + belongs_to :to, User field :title, :string field :to_read, :boolean, default: false diff --git a/lib/philomena/conversations/message.ex b/lib/philomena/conversations/message.ex index a015a87d..7ee9c008 100644 --- a/lib/philomena/conversations/message.ex +++ b/lib/philomena/conversations/message.ex @@ -2,9 +2,12 @@ defmodule Philomena.Conversations.Message do use Ecto.Schema import Ecto.Changeset + alias Philomena.Conversations.Conversation + alias Philomena.Users.User + schema "messages" do - belongs_to :conversation, Philomena.Conversations.Conversation - belongs_to :from, Philomena.Users.User + belongs_to :conversation, Conversation + belongs_to :from, User field :body, :string diff --git a/lib/philomena/dnp_entries/dnp_entry.ex b/lib/philomena/dnp_entries/dnp_entry.ex index 0b43e853..bac17756 100644 --- a/lib/philomena/dnp_entries/dnp_entry.ex +++ b/lib/philomena/dnp_entries/dnp_entry.ex @@ -2,10 +2,13 @@ defmodule Philomena.DnpEntries.DnpEntry do use Ecto.Schema import Ecto.Changeset + alias Philomena.Tags.Tag + alias Philomena.Users.User + schema "dnp_entries" do - belongs_to :requesting_user, Philomena.Users.User - belongs_to :modifying_user, Philomena.Users.User - belongs_to :tag, Philomena.Tags.Tag + belongs_to :requesting_user, User + belongs_to :modifying_user, User + belongs_to :tag, Tag field :aasm_state, :string, default: "requested" field :dnp_type, :string diff --git a/lib/philomena/donations/donation.ex b/lib/philomena/donations/donation.ex index dceb2b37..1900ff94 100644 --- a/lib/philomena/donations/donation.ex +++ b/lib/philomena/donations/donation.ex @@ -2,8 +2,10 @@ defmodule Philomena.Donations.Donation do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "donations" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :email, :string field :amount, :decimal diff --git a/lib/philomena/duplicate_reports/duplicate_report.ex b/lib/philomena/duplicate_reports/duplicate_report.ex index 9dc0f7be..0ec457d0 100644 --- a/lib/philomena/duplicate_reports/duplicate_report.ex +++ b/lib/philomena/duplicate_reports/duplicate_report.ex @@ -2,11 +2,14 @@ defmodule Philomena.DuplicateReports.DuplicateReport do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Users.User + schema "duplicate_reports" do - belongs_to :image, Philomena.Images.Image - belongs_to :duplicate_of_image, Philomena.Images.Image - belongs_to :user, Philomena.Users.User - belongs_to :modifier, Philomena.Users.User + belongs_to :image, Image + belongs_to :duplicate_of_image, Image + belongs_to :user, User + belongs_to :modifier, User field :reason, :string field :state, :string, default: "open" diff --git a/lib/philomena/forums/forum.ex b/lib/philomena/forums/forum.ex index 35fb84f4..5b2cddda 100644 --- a/lib/philomena/forums/forum.ex +++ b/lib/philomena/forums/forum.ex @@ -2,10 +2,13 @@ defmodule Philomena.Forums.Forum do use Ecto.Schema import Ecto.Changeset + alias Philomena.Posts.Post + alias Philomena.Topics.Topic + @derive {Phoenix.Param, key: :short_name} schema "forums" do - belongs_to :last_post, Philomena.Posts.Post - belongs_to :last_topic, Philomena.Topics.Topic + belongs_to :last_post, Post + belongs_to :last_topic, Topic field :name, :string field :short_name, :string diff --git a/lib/philomena/forums/subscription.ex b/lib/philomena/forums/subscription.ex index d46646c6..538fa5db 100644 --- a/lib/philomena/forums/subscription.ex +++ b/lib/philomena/forums/subscription.ex @@ -2,11 +2,14 @@ defmodule Philomena.Forums.Subscription do use Ecto.Schema import Ecto.Changeset + alias Philomena.Forums.Forum + alias Philomena.Users.User + @primary_key false schema "forum_subscriptions" do - belongs_to :forum, Philomena.Forums.Forum, primary_key: true - belongs_to :user, Philomena.Users.User, primary_key: true + belongs_to :forum, Forum, primary_key: true + belongs_to :user, User, primary_key: true end @doc false diff --git a/lib/philomena/galleries/gallery.ex b/lib/philomena/galleries/gallery.ex index 014716d5..eb25398f 100644 --- a/lib/philomena/galleries/gallery.ex +++ b/lib/philomena/galleries/gallery.ex @@ -2,9 +2,12 @@ defmodule Philomena.Galleries.Gallery do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Users.User + schema "galleries" do - belongs_to :thumbnail, Philomena.Images.Image, source: :thumbnail_id - belongs_to :creator, Philomena.Users.User, source: :creator_id + belongs_to :thumbnail, Image, source: :thumbnail_id + belongs_to :creator, User, source: :creator_id field :title, :string field :spoiler_warning, :string diff --git a/lib/philomena/galleries/interaction.ex b/lib/philomena/galleries/interaction.ex index ce387d70..b50983ee 100644 --- a/lib/philomena/galleries/interaction.ex +++ b/lib/philomena/galleries/interaction.ex @@ -2,11 +2,14 @@ defmodule Philomena.Galleries.Interaction do use Ecto.Schema import Ecto.Changeset + alias Philomena.Galleries.Gallery + alias Philomena.Images.Image + @primary_key false schema "gallery_interactions" do - belongs_to :gallery, Philomena.Galleries.Gallery, primary_key: true - belongs_to :image, Philomena.Images.Image, primary_key: true + belongs_to :gallery, Gallery, primary_key: true + belongs_to :image, Image, primary_key: true field :position, :integer end diff --git a/lib/philomena/galleries/subscription.ex b/lib/philomena/galleries/subscription.ex index 543af322..a887ca9b 100644 --- a/lib/philomena/galleries/subscription.ex +++ b/lib/philomena/galleries/subscription.ex @@ -2,11 +2,14 @@ defmodule Philomena.Galleries.Subscription do use Ecto.Schema import Ecto.Changeset + alias Philomena.Galleries.Gallery + alias Philomena.Users.User + @primary_key false schema "gallery_subscriptions" do - belongs_to :gallery, Philomena.Galleries.Gallery, primary_key: true - belongs_to :user, Philomena.Users.User, primary_key: true + belongs_to :gallery, Gallery, primary_key: true + belongs_to :user, User, primary_key: true end @doc false diff --git a/lib/philomena/image_faves.ex b/lib/philomena/image_faves.ex new file mode 100644 index 00000000..7fac0a80 --- /dev/null +++ b/lib/philomena/image_faves.ex @@ -0,0 +1,104 @@ +defmodule Philomena.ImageFaves do + @moduledoc """ + The ImageFaves context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.ImageFaves.ImageFave + + @doc """ + Returns the list of image_faves. + + ## Examples + + iex> list_image_faves() + [%ImageFave{}, ...] + + """ + def list_image_faves do + Repo.all(ImageFave) + end + + @doc """ + Gets a single image_fave. + + Raises `Ecto.NoResultsError` if the Image fave does not exist. + + ## Examples + + iex> get_image_fave!(123) + %ImageFave{} + + iex> get_image_fave!(456) + ** (Ecto.NoResultsError) + + """ + def get_image_fave!(id), do: Repo.get!(ImageFave, id) + + @doc """ + Creates a image_fave. + + ## Examples + + iex> create_image_fave(%{field: value}) + {:ok, %ImageFave{}} + + iex> create_image_fave(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_image_fave(attrs \\ %{}) do + %ImageFave{} + |> ImageFave.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a image_fave. + + ## Examples + + iex> update_image_fave(image_fave, %{field: new_value}) + {:ok, %ImageFave{}} + + iex> update_image_fave(image_fave, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_image_fave(%ImageFave{} = image_fave, attrs) do + image_fave + |> ImageFave.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a ImageFave. + + ## Examples + + iex> delete_image_fave(image_fave) + {:ok, %ImageFave{}} + + iex> delete_image_fave(image_fave) + {:error, %Ecto.Changeset{}} + + """ + def delete_image_fave(%ImageFave{} = image_fave) do + Repo.delete(image_fave) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking image_fave changes. + + ## Examples + + iex> change_image_fave(image_fave) + %Ecto.Changeset{source: %ImageFave{}} + + """ + def change_image_fave(%ImageFave{} = image_fave) do + ImageFave.changeset(image_fave, %{}) + end +end diff --git a/lib/philomena/image_faves/image_fave.ex b/lib/philomena/image_faves/image_fave.ex new file mode 100644 index 00000000..de05db90 --- /dev/null +++ b/lib/philomena/image_faves/image_fave.ex @@ -0,0 +1,22 @@ +defmodule Philomena.ImageFaves.ImageFave do + use Ecto.Schema + import Ecto.Changeset + + alias Philomena.Images.Image + alias Philomena.Users.User + + @primary_key false + + schema "image_faves" do + belongs_to :user, User, primary_key: true + belongs_to :image, Image, primary_key: true + timestamps(inserted_at: :created_at, updated_at: false) + end + + @doc false + def changeset(image_fave, attrs) do + image_fave + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/lib/philomena/image_features.ex b/lib/philomena/image_features.ex new file mode 100644 index 00000000..49a8235a --- /dev/null +++ b/lib/philomena/image_features.ex @@ -0,0 +1,104 @@ +defmodule Philomena.ImageFeatures do + @moduledoc """ + The ImageFeatures context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.ImageFeatures.ImageFeature + + @doc """ + Returns the list of image_features. + + ## Examples + + iex> list_image_features() + [%ImageFeature{}, ...] + + """ + def list_image_features do + Repo.all(ImageFeature) + end + + @doc """ + Gets a single image_feature. + + Raises `Ecto.NoResultsError` if the Image feature does not exist. + + ## Examples + + iex> get_image_feature!(123) + %ImageFeature{} + + iex> get_image_feature!(456) + ** (Ecto.NoResultsError) + + """ + def get_image_feature!(id), do: Repo.get!(ImageFeature, id) + + @doc """ + Creates a image_feature. + + ## Examples + + iex> create_image_feature(%{field: value}) + {:ok, %ImageFeature{}} + + iex> create_image_feature(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_image_feature(attrs \\ %{}) do + %ImageFeature{} + |> ImageFeature.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a image_feature. + + ## Examples + + iex> update_image_feature(image_feature, %{field: new_value}) + {:ok, %ImageFeature{}} + + iex> update_image_feature(image_feature, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_image_feature(%ImageFeature{} = image_feature, attrs) do + image_feature + |> ImageFeature.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a ImageFeature. + + ## Examples + + iex> delete_image_feature(image_feature) + {:ok, %ImageFeature{}} + + iex> delete_image_feature(image_feature) + {:error, %Ecto.Changeset{}} + + """ + def delete_image_feature(%ImageFeature{} = image_feature) do + Repo.delete(image_feature) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking image_feature changes. + + ## Examples + + iex> change_image_feature(image_feature) + %Ecto.Changeset{source: %ImageFeature{}} + + """ + def change_image_feature(%ImageFeature{} = image_feature) do + ImageFeature.changeset(image_feature, %{}) + end +end diff --git a/lib/philomena/image_features/image_feature.ex b/lib/philomena/image_features/image_feature.ex new file mode 100644 index 00000000..030a0b6d --- /dev/null +++ b/lib/philomena/image_features/image_feature.ex @@ -0,0 +1,23 @@ +defmodule Philomena.ImageFeatures.ImageFeature do + use Ecto.Schema + import Ecto.Changeset + + alias Philomena.Images.Image + alias Philomena.Users.User + + @primary_key false + + schema "image_features" do + belongs_to :image, Image + belongs_to :user, User + + timestamps(inserted_at: :created_at) + end + + @doc false + def changeset(image_feature, attrs) do + image_feature + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/lib/philomena/image_hides.ex b/lib/philomena/image_hides.ex new file mode 100644 index 00000000..1e2fc3b6 --- /dev/null +++ b/lib/philomena/image_hides.ex @@ -0,0 +1,104 @@ +defmodule Philomena.ImageHides do + @moduledoc """ + The ImageHides context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.ImageHides.ImageHide + + @doc """ + Returns the list of image_hides. + + ## Examples + + iex> list_image_hides() + [%ImageHide{}, ...] + + """ + def list_image_hides do + Repo.all(ImageHide) + end + + @doc """ + Gets a single image_hide. + + Raises `Ecto.NoResultsError` if the Image hide does not exist. + + ## Examples + + iex> get_image_hide!(123) + %ImageHide{} + + iex> get_image_hide!(456) + ** (Ecto.NoResultsError) + + """ + def get_image_hide!(id), do: Repo.get!(ImageHide, id) + + @doc """ + Creates a image_hide. + + ## Examples + + iex> create_image_hide(%{field: value}) + {:ok, %ImageHide{}} + + iex> create_image_hide(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_image_hide(attrs \\ %{}) do + %ImageHide{} + |> ImageHide.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a image_hide. + + ## Examples + + iex> update_image_hide(image_hide, %{field: new_value}) + {:ok, %ImageHide{}} + + iex> update_image_hide(image_hide, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_image_hide(%ImageHide{} = image_hide, attrs) do + image_hide + |> ImageHide.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a ImageHide. + + ## Examples + + iex> delete_image_hide(image_hide) + {:ok, %ImageHide{}} + + iex> delete_image_hide(image_hide) + {:error, %Ecto.Changeset{}} + + """ + def delete_image_hide(%ImageHide{} = image_hide) do + Repo.delete(image_hide) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking image_hide changes. + + ## Examples + + iex> change_image_hide(image_hide) + %Ecto.Changeset{source: %ImageHide{}} + + """ + def change_image_hide(%ImageHide{} = image_hide) do + ImageHide.changeset(image_hide, %{}) + end +end diff --git a/lib/philomena/image_hides/image_hide.ex b/lib/philomena/image_hides/image_hide.ex new file mode 100644 index 00000000..ce6cc239 --- /dev/null +++ b/lib/philomena/image_hides/image_hide.ex @@ -0,0 +1,22 @@ +defmodule Philomena.ImageHides.ImageHide do + use Ecto.Schema + import Ecto.Changeset + + alias Philomena.Images.Image + alias Philomena.Users.User + + @primary_key false + + schema "image_hides" do + belongs_to :user, User, primary_key: true + belongs_to :image, Image, primary_key: true + timestamps(inserted_at: :created_at, updated_at: false) + end + + @doc false + def changeset(image_hide, attrs) do + image_hide + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/lib/philomena/image_intensities.ex b/lib/philomena/image_intensities.ex new file mode 100644 index 00000000..4b0bc73d --- /dev/null +++ b/lib/philomena/image_intensities.ex @@ -0,0 +1,104 @@ +defmodule Philomena.ImageIntensities do + @moduledoc """ + The ImageIntensities context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.ImageIntensities.ImageIntensity + + @doc """ + Returns the list of image_intensities. + + ## Examples + + iex> list_image_intensities() + [%ImageIntensity{}, ...] + + """ + def list_image_intensities do + Repo.all(ImageIntensity) + end + + @doc """ + Gets a single image_intensity. + + Raises `Ecto.NoResultsError` if the Image intensity does not exist. + + ## Examples + + iex> get_image_intensity!(123) + %ImageIntensity{} + + iex> get_image_intensity!(456) + ** (Ecto.NoResultsError) + + """ + def get_image_intensity!(id), do: Repo.get!(ImageIntensity, id) + + @doc """ + Creates a image_intensity. + + ## Examples + + iex> create_image_intensity(%{field: value}) + {:ok, %ImageIntensity{}} + + iex> create_image_intensity(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_image_intensity(attrs \\ %{}) do + %ImageIntensity{} + |> ImageIntensity.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a image_intensity. + + ## Examples + + iex> update_image_intensity(image_intensity, %{field: new_value}) + {:ok, %ImageIntensity{}} + + iex> update_image_intensity(image_intensity, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_image_intensity(%ImageIntensity{} = image_intensity, attrs) do + image_intensity + |> ImageIntensity.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a ImageIntensity. + + ## Examples + + iex> delete_image_intensity(image_intensity) + {:ok, %ImageIntensity{}} + + iex> delete_image_intensity(image_intensity) + {:error, %Ecto.Changeset{}} + + """ + def delete_image_intensity(%ImageIntensity{} = image_intensity) do + Repo.delete(image_intensity) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking image_intensity changes. + + ## Examples + + iex> change_image_intensity(image_intensity) + %Ecto.Changeset{source: %ImageIntensity{}} + + """ + def change_image_intensity(%ImageIntensity{} = image_intensity) do + ImageIntensity.changeset(image_intensity, %{}) + end +end diff --git a/lib/philomena/images/intensities.ex b/lib/philomena/image_intensities/image_intensity.ex similarity index 57% rename from lib/philomena/images/intensities.ex rename to lib/philomena/image_intensities/image_intensity.ex index 8f942cca..2ab93a6d 100644 --- a/lib/philomena/images/intensities.ex +++ b/lib/philomena/image_intensities/image_intensity.ex @@ -1,11 +1,13 @@ -defmodule Philomena.Images.Intensities do +defmodule Philomena.ImageIntensities.ImageIntensity do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + @primary_key false schema "image_intensities" do - belongs_to :image, Philomena.Images.Image, primary_key: true + belongs_to :image, Image, primary_key: true field :nw, :float field :ne, :float @@ -14,8 +16,8 @@ defmodule Philomena.Images.Intensities do end @doc false - def changeset(intensities, attrs) do - intensities + def changeset(image_intensity, attrs) do + image_intensity |> cast(attrs, []) |> validate_required([]) end diff --git a/lib/philomena/image_votes.ex b/lib/philomena/image_votes.ex new file mode 100644 index 00000000..8dc6451c --- /dev/null +++ b/lib/philomena/image_votes.ex @@ -0,0 +1,104 @@ +defmodule Philomena.ImageVotes do + @moduledoc """ + The ImageVotes context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.ImageVotes.ImageVote + + @doc """ + Returns the list of image_votes. + + ## Examples + + iex> list_image_votes() + [%ImageVote{}, ...] + + """ + def list_image_votes do + Repo.all(ImageVote) + end + + @doc """ + Gets a single image_vote. + + Raises `Ecto.NoResultsError` if the Image vote does not exist. + + ## Examples + + iex> get_image_vote!(123) + %ImageVote{} + + iex> get_image_vote!(456) + ** (Ecto.NoResultsError) + + """ + def get_image_vote!(id), do: Repo.get!(ImageVote, id) + + @doc """ + Creates a image_vote. + + ## Examples + + iex> create_image_vote(%{field: value}) + {:ok, %ImageVote{}} + + iex> create_image_vote(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_image_vote(attrs \\ %{}) do + %ImageVote{} + |> ImageVote.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a image_vote. + + ## Examples + + iex> update_image_vote(image_vote, %{field: new_value}) + {:ok, %ImageVote{}} + + iex> update_image_vote(image_vote, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_image_vote(%ImageVote{} = image_vote, attrs) do + image_vote + |> ImageVote.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a ImageVote. + + ## Examples + + iex> delete_image_vote(image_vote) + {:ok, %ImageVote{}} + + iex> delete_image_vote(image_vote) + {:error, %Ecto.Changeset{}} + + """ + def delete_image_vote(%ImageVote{} = image_vote) do + Repo.delete(image_vote) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking image_vote changes. + + ## Examples + + iex> change_image_vote(image_vote) + %Ecto.Changeset{source: %ImageVote{}} + + """ + def change_image_vote(%ImageVote{} = image_vote) do + ImageVote.changeset(image_vote, %{}) + end +end diff --git a/lib/philomena/images/vote.ex b/lib/philomena/image_votes/image_vote.ex similarity index 50% rename from lib/philomena/images/vote.ex rename to lib/philomena/image_votes/image_vote.ex index b2c3bea0..bca9b8d8 100644 --- a/lib/philomena/images/vote.ex +++ b/lib/philomena/image_votes/image_vote.ex @@ -1,19 +1,22 @@ -defmodule Philomena.Images.Vote do +defmodule Philomena.ImageVotes.ImageVote do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Users.User + @primary_key false schema "image_votes" do - belongs_to :user, Philomena.Users.User, primary_key: true - belongs_to :image, Philomena.Images.Image, primary_key: true + belongs_to :user, User, primary_key: true + belongs_to :image, Image, primary_key: true field :up, :boolean timestamps(inserted_at: :created_at, updated_at: false) end @doc false - def changeset(vote, attrs) do - vote + def changeset(image_vote, attrs) do + image_vote |> cast(attrs, []) |> validate_required([]) end diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index a83fa577..85d48ce1 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -104,198 +104,6 @@ defmodule Philomena.Images do Image.changeset(image, %{}) end - alias Philomena.Images.Feature - - @doc """ - Returns the list of image_features. - - ## Examples - - iex> list_image_features() - [%Feature{}, ...] - - """ - def list_image_features do - Repo.all(Feature) - end - - @doc """ - Gets a single features. - - Raises `Ecto.NoResultsError` if the Feature does not exist. - - ## Examples - - iex> get_features!(123) - %Feature{} - - iex> get_features!(456) - ** (Ecto.NoResultsError) - - """ - def get_features!(id), do: Repo.get!(Feature, id) - - @doc """ - Creates a features. - - ## Examples - - iex> create_features(%{field: value}) - {:ok, %Feature{}} - - iex> create_features(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_features(attrs \\ %{}) do - %Feature{} - |> Feature.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a features. - - ## Examples - - iex> update_features(features, %{field: new_value}) - {:ok, %Feature{}} - - iex> update_features(features, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_features(%Feature{} = features, attrs) do - features - |> Feature.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a Feature. - - ## Examples - - iex> delete_features(features) - {:ok, %Feature{}} - - iex> delete_features(features) - {:error, %Ecto.Changeset{}} - - """ - def delete_features(%Feature{} = features) do - Repo.delete(features) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking features changes. - - ## Examples - - iex> change_features(features) - %Ecto.Changeset{source: %Feature{}} - - """ - def change_features(%Feature{} = features) do - Feature.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 """ @@ -391,196 +199,4 @@ defmodule Philomena.Images do def change_subscription(%Subscription{} = subscription) do Subscription.changeset(subscription, %{}) end - - alias Philomena.Images.SourceChange - - @doc """ - Returns the list of source_changes. - - ## Examples - - iex> list_source_changes() - [%SourceChange{}, ...] - - """ - def list_source_changes do - Repo.all(SourceChange) - end - - @doc """ - Gets a single source_change. - - Raises `Ecto.NoResultsError` if the Source change does not exist. - - ## Examples - - iex> get_source_change!(123) - %SourceChange{} - - iex> get_source_change!(456) - ** (Ecto.NoResultsError) - - """ - def get_source_change!(id), do: Repo.get!(SourceChange, id) - - @doc """ - Creates a source_change. - - ## Examples - - iex> create_source_change(%{field: value}) - {:ok, %SourceChange{}} - - iex> create_source_change(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_source_change(attrs \\ %{}) do - %SourceChange{} - |> SourceChange.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a source_change. - - ## Examples - - iex> update_source_change(source_change, %{field: new_value}) - {:ok, %SourceChange{}} - - iex> update_source_change(source_change, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_source_change(%SourceChange{} = source_change, attrs) do - source_change - |> SourceChange.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a SourceChange. - - ## Examples - - iex> delete_source_change(source_change) - {:ok, %SourceChange{}} - - iex> delete_source_change(source_change) - {:error, %Ecto.Changeset{}} - - """ - def delete_source_change(%SourceChange{} = source_change) do - Repo.delete(source_change) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking source_change changes. - - ## Examples - - iex> change_source_change(source_change) - %Ecto.Changeset{source: %SourceChange{}} - - """ - def change_source_change(%SourceChange{} = source_change) do - SourceChange.changeset(source_change, %{}) - end - - alias Philomena.Images.TagChange - - @doc """ - Returns the list of tag_changes. - - ## Examples - - iex> list_tag_changes() - [%TagChange{}, ...] - - """ - def list_tag_changes do - Repo.all(TagChange) - end - - @doc """ - Gets a single tag_change. - - Raises `Ecto.NoResultsError` if the Tag change does not exist. - - ## Examples - - iex> get_tag_change!(123) - %TagChange{} - - iex> get_tag_change!(456) - ** (Ecto.NoResultsError) - - """ - def get_tag_change!(id), do: Repo.get!(TagChange, id) - - @doc """ - Creates a tag_change. - - ## Examples - - iex> create_tag_change(%{field: value}) - {:ok, %TagChange{}} - - iex> create_tag_change(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_tag_change(attrs \\ %{}) do - %TagChange{} - |> TagChange.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a tag_change. - - ## Examples - - iex> update_tag_change(tag_change, %{field: new_value}) - {:ok, %TagChange{}} - - iex> update_tag_change(tag_change, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_tag_change(%TagChange{} = tag_change, attrs) do - tag_change - |> TagChange.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a TagChange. - - ## Examples - - iex> delete_tag_change(tag_change) - {:ok, %TagChange{}} - - iex> delete_tag_change(tag_change) - {:error, %Ecto.Changeset{}} - - """ - def delete_tag_change(%TagChange{} = tag_change) do - Repo.delete(tag_change) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking tag_change changes. - - ## Examples - - iex> change_tag_change(tag_change) - %Ecto.Changeset{source: %TagChange{}} - - """ - def change_tag_change(%TagChange{} = tag_change) do - TagChange.changeset(tag_change, %{}) - end end diff --git a/lib/philomena/images/fave.ex b/lib/philomena/images/fave.ex deleted file mode 100644 index 34447de5..00000000 --- a/lib/philomena/images/fave.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Philomena.Images.Fave do - use Ecto.Schema - import Ecto.Changeset - - @primary_key false - - schema "image_faves" do - belongs_to :user, Philomena.Users.User, primary_key: true - belongs_to :image, Philomena.Images.Image, primary_key: true - timestamps(inserted_at: :created_at, updated_at: false) - end - - @doc false - def changeset(fave, attrs) do - fave - |> cast(attrs, []) - |> validate_required([]) - end -end diff --git a/lib/philomena/images/feature.ex b/lib/philomena/images/feature.ex deleted file mode 100644 index d8d19677..00000000 --- a/lib/philomena/images/feature.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule Philomena.Images.Feature 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 diff --git a/lib/philomena/images/hide.ex b/lib/philomena/images/hide.ex deleted file mode 100644 index 9343a2be..00000000 --- a/lib/philomena/images/hide.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Philomena.Images.Hide do - use Ecto.Schema - import Ecto.Changeset - - @primary_key false - - schema "image_hides" do - belongs_to :user, Philomena.Users.User, primary_key: true - belongs_to :image, Philomena.Images.Image, primary_key: true - timestamps(inserted_at: :created_at, updated_at: false) - end - - @doc false - def changeset(hide, attrs) do - hide - |> cast(attrs, []) - |> validate_required([]) - end -end diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index 285c29ad..64f0ad20 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -8,15 +8,22 @@ defmodule Philomena.Images.Image do import Ecto.Changeset + alias Philomena.ImageVotes.ImageVote + alias Philomena.ImageFaves.ImageFave + alias Philomena.ImageHides.ImageHide + alias Philomena.Users.User + alias Philomena.Images.Tagging + alias Philomena.Galleries + schema "images" do - belongs_to :user, Philomena.Users.User - belongs_to :deleter, Philomena.Users.User, source: :deleted_by_id - has_many :upvotes, Philomena.Images.Vote, where: [up: true] - has_many :downvotes, Philomena.Images.Vote, where: [up: false] - has_many :faves, Philomena.Images.Fave - has_many :hides, Philomena.Images.Hide - has_many :taggings, Philomena.Images.Tagging - has_many :gallery_interactions, Philomena.Galleries.Interaction + belongs_to :user, User + belongs_to :deleter, User, source: :deleted_by_id + has_many :upvotes, ImageVote, where: [up: true] + has_many :downvotes, ImageVote, where: [up: false] + has_many :faves, ImageFave + has_many :hides, ImageHide + has_many :taggings, Tagging + has_many :gallery_interactions, Galleries.Interaction has_many :tags, through: [:taggings, :tag] has_many :upvoters, through: [:upvotes, :user] has_many :downvoters, through: [:downvotes, :user] diff --git a/lib/philomena/images/subscription.ex b/lib/philomena/images/subscription.ex index 966b6f9d..acfcfadf 100644 --- a/lib/philomena/images/subscription.ex +++ b/lib/philomena/images/subscription.ex @@ -2,11 +2,14 @@ defmodule Philomena.Images.Subscription do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Users.User + @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 + belongs_to :image, Image, primary_key: true + belongs_to :user, User, primary_key: true end @doc false diff --git a/lib/philomena/images/tagging.ex b/lib/philomena/images/tagging.ex index e2114a05..e3f8c459 100644 --- a/lib/philomena/images/tagging.ex +++ b/lib/philomena/images/tagging.ex @@ -2,11 +2,14 @@ defmodule Philomena.Images.Tagging do use Ecto.Schema import Ecto.Changeset + alias Philomena.Images.Image + alias Philomena.Tags.Tag + @primary_key false schema "image_taggings" do - belongs_to :image, Philomena.Images.Image, primary_key: true - belongs_to :tag, Philomena.Tags.Tag, primary_key: true + belongs_to :image, Image, primary_key: true + belongs_to :tag, Tag, primary_key: true end @doc false diff --git a/lib/philomena/mod_notes/mod_note.ex b/lib/philomena/mod_notes/mod_note.ex index fd344947..bf1674cb 100644 --- a/lib/philomena/mod_notes/mod_note.ex +++ b/lib/philomena/mod_notes/mod_note.ex @@ -2,8 +2,10 @@ defmodule Philomena.ModNotes.ModNote do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "mod_notes" do - belongs_to :moderator, Philomena.Users.User + belongs_to :moderator, User # fixme: rails polymorphic relation field :notable_id, :integer diff --git a/lib/philomena/notifications/unread_notification.ex b/lib/philomena/notifications/unread_notification.ex index 0d4e2a5d..1d111141 100644 --- a/lib/philomena/notifications/unread_notification.ex +++ b/lib/philomena/notifications/unread_notification.ex @@ -2,11 +2,14 @@ defmodule Philomena.Notifications.UnreadNotification do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + alias Philomena.Notifications.Notification + @primary_key false schema "unread_notifications" do - belongs_to :user, Philomena.Users.User, primary_key: true - belongs_to :notification, Philomena.Notifications.Notification, primary_key: true + belongs_to :user, User, primary_key: true + belongs_to :notification, Notification, primary_key: true end @doc false diff --git a/lib/philomena/poll_options/poll_option.ex b/lib/philomena/poll_options/poll_option.ex index 9deef755..3c6e55d4 100644 --- a/lib/philomena/poll_options/poll_option.ex +++ b/lib/philomena/poll_options/poll_option.ex @@ -2,8 +2,10 @@ defmodule Philomena.PollOptions.PollOption do use Ecto.Schema import Ecto.Changeset + alias Philomena.Polls.Poll + schema "poll_options" do - belongs_to :poll, Philomena.Polls.Poll + belongs_to :poll, Poll field :label, :string field :vote_count, :integer, default: 0 diff --git a/lib/philomena/poll_votes/poll_vote.ex b/lib/philomena/poll_votes/poll_vote.ex index 037d2dda..6f87abfb 100644 --- a/lib/philomena/poll_votes/poll_vote.ex +++ b/lib/philomena/poll_votes/poll_vote.ex @@ -2,9 +2,12 @@ defmodule Philomena.PollVotes.PollVote do use Ecto.Schema import Ecto.Changeset + alias Philomena.PollOptions.PollOption + alias Philomena.Users.User + schema "poll_votes" do - belongs_to :poll_option, Philomena.PollOptions.PollOption - belongs_to :user, Philomena.Users.User + belongs_to :poll_option, PollOption + belongs_to :user, User field :rank, :integer diff --git a/lib/philomena/polls/poll.ex b/lib/philomena/polls/poll.ex index 0e795511..2881524d 100644 --- a/lib/philomena/polls/poll.ex +++ b/lib/philomena/polls/poll.ex @@ -2,9 +2,12 @@ defmodule Philomena.Polls.Poll do use Ecto.Schema import Ecto.Changeset + alias Philomena.Topics.Topic + alias Philomena.Users.User + schema "polls" do - belongs_to :topic, Philomena.Topics.Topic - belongs_to :deleted_by, Philomena.Users.User + belongs_to :topic, Topic + belongs_to :deleted_by, User field :title, :string field :vote_method, :string diff --git a/lib/philomena/posts/post.ex b/lib/philomena/posts/post.ex index 08ca746c..953f486d 100644 --- a/lib/philomena/posts/post.ex +++ b/lib/philomena/posts/post.ex @@ -2,10 +2,13 @@ defmodule Philomena.Posts.Post do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + alias Philomena.Topics.Topic + schema "posts" do - belongs_to :user, Philomena.Users.User - belongs_to :topic, Philomena.Topics.Topic - belongs_to :deleted_by, Philomena.Users.User + belongs_to :user, User + belongs_to :topic, Topic + belongs_to :deleted_by, User field :body, :string field :edit_reason, :string diff --git a/lib/philomena/reports/report.ex b/lib/philomena/reports/report.ex index 46372532..5cadee7f 100644 --- a/lib/philomena/reports/report.ex +++ b/lib/philomena/reports/report.ex @@ -2,9 +2,11 @@ defmodule Philomena.Reports.Report do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "reports" do - belongs_to :user, Philomena.Users.User - belongs_to :admin, Philomena.Users.User + belongs_to :user, User + belongs_to :admin, User field :ip, EctoNetwork.INET field :fingerprint, :string diff --git a/lib/philomena/site_notices/site_notice.ex b/lib/philomena/site_notices/site_notice.ex index 85ee4492..42928ada 100644 --- a/lib/philomena/site_notices/site_notice.ex +++ b/lib/philomena/site_notices/site_notice.ex @@ -2,8 +2,10 @@ defmodule Philomena.SiteNotices.SiteNotice do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "site_notices" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :title, :string field :text, :string diff --git a/lib/philomena/source_changes.ex b/lib/philomena/source_changes.ex new file mode 100644 index 00000000..30e6b057 --- /dev/null +++ b/lib/philomena/source_changes.ex @@ -0,0 +1,104 @@ +defmodule Philomena.SourceChanges do + @moduledoc """ + The SourceChanges context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.SourceChanges.SourceChange + + @doc """ + Returns the list of source_changes. + + ## Examples + + iex> list_source_changes() + [%SourceChange{}, ...] + + """ + def list_source_changes do + Repo.all(SourceChange) + end + + @doc """ + Gets a single source_change. + + Raises `Ecto.NoResultsError` if the Source change does not exist. + + ## Examples + + iex> get_source_change!(123) + %SourceChange{} + + iex> get_source_change!(456) + ** (Ecto.NoResultsError) + + """ + def get_source_change!(id), do: Repo.get!(SourceChange, id) + + @doc """ + Creates a source_change. + + ## Examples + + iex> create_source_change(%{field: value}) + {:ok, %SourceChange{}} + + iex> create_source_change(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_source_change(attrs \\ %{}) do + %SourceChange{} + |> SourceChange.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a source_change. + + ## Examples + + iex> update_source_change(source_change, %{field: new_value}) + {:ok, %SourceChange{}} + + iex> update_source_change(source_change, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_source_change(%SourceChange{} = source_change, attrs) do + source_change + |> SourceChange.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a SourceChange. + + ## Examples + + iex> delete_source_change(source_change) + {:ok, %SourceChange{}} + + iex> delete_source_change(source_change) + {:error, %Ecto.Changeset{}} + + """ + def delete_source_change(%SourceChange{} = source_change) do + Repo.delete(source_change) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking source_change changes. + + ## Examples + + iex> change_source_change(source_change) + %Ecto.Changeset{source: %SourceChange{}} + + """ + def change_source_change(%SourceChange{} = source_change) do + SourceChange.changeset(source_change, %{}) + end +end diff --git a/lib/philomena/images/source_change.ex b/lib/philomena/source_changes/source_change.ex similarity index 91% rename from lib/philomena/images/source_change.ex rename to lib/philomena/source_changes/source_change.ex index 533dc1cf..f46383d3 100644 --- a/lib/philomena/images/source_change.ex +++ b/lib/philomena/source_changes/source_change.ex @@ -1,4 +1,4 @@ -defmodule Philomena.Images.SourceChange do +defmodule Philomena.SourceChanges.SourceChange do use Ecto.Schema import Ecto.Changeset diff --git a/lib/philomena/tag_changes.ex b/lib/philomena/tag_changes.ex new file mode 100644 index 00000000..287cd79a --- /dev/null +++ b/lib/philomena/tag_changes.ex @@ -0,0 +1,104 @@ +defmodule Philomena.TagChanges do + @moduledoc """ + The TagChanges context. + """ + + import Ecto.Query, warn: false + alias Philomena.Repo + + alias Philomena.TagChanges.TagChange + + @doc """ + Returns the list of tag_changes. + + ## Examples + + iex> list_tag_changes() + [%TagChange{}, ...] + + """ + def list_tag_changes do + Repo.all(TagChange) + end + + @doc """ + Gets a single tag_change. + + Raises `Ecto.NoResultsError` if the Tag change does not exist. + + ## Examples + + iex> get_tag_change!(123) + %TagChange{} + + iex> get_tag_change!(456) + ** (Ecto.NoResultsError) + + """ + def get_tag_change!(id), do: Repo.get!(TagChange, id) + + @doc """ + Creates a tag_change. + + ## Examples + + iex> create_tag_change(%{field: value}) + {:ok, %TagChange{}} + + iex> create_tag_change(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_tag_change(attrs \\ %{}) do + %TagChange{} + |> TagChange.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a tag_change. + + ## Examples + + iex> update_tag_change(tag_change, %{field: new_value}) + {:ok, %TagChange{}} + + iex> update_tag_change(tag_change, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_tag_change(%TagChange{} = tag_change, attrs) do + tag_change + |> TagChange.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a TagChange. + + ## Examples + + iex> delete_tag_change(tag_change) + {:ok, %TagChange{}} + + iex> delete_tag_change(tag_change) + {:error, %Ecto.Changeset{}} + + """ + def delete_tag_change(%TagChange{} = tag_change) do + Repo.delete(tag_change) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking tag_change changes. + + ## Examples + + iex> change_tag_change(tag_change) + %Ecto.Changeset{source: %TagChange{}} + + """ + def change_tag_change(%TagChange{} = tag_change) do + TagChange.changeset(tag_change, %{}) + end +end diff --git a/lib/philomena/images/tag_change.ex b/lib/philomena/tag_changes/tag_change.ex similarity index 93% rename from lib/philomena/images/tag_change.ex rename to lib/philomena/tag_changes/tag_change.ex index 7f6f114a..20be3ba4 100644 --- a/lib/philomena/images/tag_change.ex +++ b/lib/philomena/tag_changes/tag_change.ex @@ -1,4 +1,4 @@ -defmodule Philomena.Images.TagChange do +defmodule Philomena.TagChanges.TagChange do use Ecto.Schema import Ecto.Changeset diff --git a/lib/philomena/tags/implication.ex b/lib/philomena/tags/implication.ex index 2cba7872..ffe4b6ec 100644 --- a/lib/philomena/tags/implication.ex +++ b/lib/philomena/tags/implication.ex @@ -2,11 +2,13 @@ defmodule Philomena.Tags.Implication do use Ecto.Schema import Ecto.Changeset + alias Philomena.Tags.Tag + @primary_key false schema "tags_implied_tags" do - belongs_to :tag, Philomena.Tags.Tag, primary_key: true - belongs_to :implied_tag, Philomena.Tags.Tag, primary_key: true + belongs_to :tag, Tag, primary_key: true + belongs_to :implied_tag, Tag, primary_key: true end @doc false diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 6e764a56..8c691fb3 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -7,11 +7,13 @@ defmodule Philomena.Tags.Tag do index_name: "tags", doc_type: "tag" + alias Philomena.Tags.Tag + schema "tags" do - belongs_to :aliased_tag, Philomena.Tags.Tag, source: :aliased_tag_id - has_many :aliases, Philomena.Tags.Tag, foreign_key: :aliased_tag_id - many_to_many :implied_tags, Philomena.Tags.Tag, join_through: "tags_implied_tags", join_keys: [tag_id: :id, implied_tag_id: :id] - many_to_many :implied_by_tags, Philomena.Tags.Tag, join_through: "tags_implied_tags", join_keys: [implied_tag_id: :id, tag_id: :id] + belongs_to :aliased_tag, Tag, source: :aliased_tag_id + has_many :aliases, Tag, foreign_key: :aliased_tag_id + many_to_many :implied_tags, Tag, join_through: "tags_implied_tags", join_keys: [tag_id: :id, implied_tag_id: :id] + many_to_many :implied_by_tags, Tag, join_through: "tags_implied_tags", join_keys: [implied_tag_id: :id, tag_id: :id] field :slug, :string field :name, :string diff --git a/lib/philomena/topics/topic.ex b/lib/philomena/topics/topic.ex index 77dd3ddb..e6146821 100644 --- a/lib/philomena/topics/topic.ex +++ b/lib/philomena/topics/topic.ex @@ -2,14 +2,19 @@ defmodule Philomena.Topics.Topic do use Ecto.Schema import Ecto.Changeset + alias Philomena.Forums.Forum + alias Philomena.Users.User + alias Philomena.Polls.Poll + alias Philomena.Posts.Post + @derive {Phoenix.Param, key: :slug} schema "topics" do - belongs_to :user, Philomena.Users.User - belongs_to :deleted_by, Philomena.Users.User - belongs_to :locked_by, Philomena.Users.User - belongs_to :last_post, Philomena.Posts.Post - belongs_to :forum, Philomena.Forums.Forum - has_one :poll, Philomena.Polls.Poll + belongs_to :user, User + belongs_to :deleted_by, User + belongs_to :locked_by, User + belongs_to :last_post, Post + belongs_to :forum, Forum + has_one :poll, Poll field :title, :string field :post_count, :integer, default: 0 diff --git a/lib/philomena/user_fingerprints/user_fingerprint.ex b/lib/philomena/user_fingerprints/user_fingerprint.ex index 4b7fb79b..d9810da8 100644 --- a/lib/philomena/user_fingerprints/user_fingerprint.ex +++ b/lib/philomena/user_fingerprints/user_fingerprint.ex @@ -2,8 +2,10 @@ defmodule Philomena.UserFingerprints.UserFingerprint do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_fingerprints" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :fingerprint, :string field :uses, :integer, default: 0 diff --git a/lib/philomena/user_ips/user_ip.ex b/lib/philomena/user_ips/user_ip.ex index 6417f3db..6885cd63 100644 --- a/lib/philomena/user_ips/user_ip.ex +++ b/lib/philomena/user_ips/user_ip.ex @@ -2,8 +2,10 @@ defmodule Philomena.UserIps.UserIp do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_ips" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :ip, EctoNetwork.INET field :uses, :integer, default: 0 diff --git a/lib/philomena/user_links/user_link.ex b/lib/philomena/user_links/user_link.ex index 2cfa7d59..f934ee9d 100644 --- a/lib/philomena/user_links/user_link.ex +++ b/lib/philomena/user_links/user_link.ex @@ -2,11 +2,14 @@ defmodule Philomena.UserLinks.UserLink do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + alias Philomena.Tags.Tag + schema "user_links" do - belongs_to :user, Philomena.Users.User - belongs_to :verified_by_user, Philomena.Users.User - belongs_to :contacted_by_user, Philomena.Users.User - belongs_to :tag, Philomena.Tags.Tag + belongs_to :user, User + belongs_to :verified_by_user, User + belongs_to :contacted_by_user, User + belongs_to :tag, Tag field :aasm_state, :string field :uri, :string diff --git a/lib/philomena/user_name_changes/user_name_change.ex b/lib/philomena/user_name_changes/user_name_change.ex index ac9f72af..06b8c765 100644 --- a/lib/philomena/user_name_changes/user_name_change.ex +++ b/lib/philomena/user_name_changes/user_name_change.ex @@ -2,8 +2,10 @@ defmodule Philomena.UserNameChanges.UserNameChange do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_name_changes" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :name, :string timestamps(inserted_at: :created_at) diff --git a/lib/philomena/user_statistics/user_statistic.ex b/lib/philomena/user_statistics/user_statistic.ex index 182b0c77..c0dbeda4 100644 --- a/lib/philomena/user_statistics/user_statistic.ex +++ b/lib/philomena/user_statistics/user_statistic.ex @@ -2,8 +2,10 @@ defmodule Philomena.UserStatistics.UserStatistic do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_statistics" do - belongs_to :user, Philomena.Users.User + belongs_to :user, User field :day, :integer, default: 0 field :uploads, :integer, default: 0 field :votes_cast, :integer, default: 0 diff --git a/lib/philomena/user_whitelists/user_whitelist.ex b/lib/philomena/user_whitelists/user_whitelist.ex index d7b290d5..e6e1bd25 100644 --- a/lib/philomena/user_whitelists/user_whitelist.ex +++ b/lib/philomena/user_whitelists/user_whitelist.ex @@ -2,7 +2,11 @@ defmodule Philomena.UserWhitelists.UserWhitelist do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + schema "user_whitelists" do + belongs_to :user, User + field :reason, :string timestamps(inserted_at: :created_at) end diff --git a/lib/philomena/users/role.ex b/lib/philomena/users/role.ex index d85b5ff4..0c5dde75 100644 --- a/lib/philomena/users/role.ex +++ b/lib/philomena/users/role.ex @@ -2,11 +2,14 @@ defmodule Philomena.Users.Role do use Ecto.Schema import Ecto.Changeset + alias Philomena.Users.User + alias Philomena.Roles.Role + @primary_key false schema "users_roles" do - belongs_to :user, Philomena.Users.User, primary_key: true - belongs_to :role, Philomena.Roles.Role, primary_key: true + belongs_to :user, User, primary_key: true + belongs_to :role, Role, primary_key: true end @doc false diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index f3b33adf..739093f6 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -13,19 +13,26 @@ defmodule Philomena.Users.User do import Ecto.Changeset + alias Philomena.Filters.Filter + alias Philomena.UserLinks.UserLink + alias Philomena.Badges + alias Philomena.Notifications.UnreadNotification + alias Philomena.Galleries.Gallery + alias Philomena.Users.User + @derive {Phoenix.Param, key: :slug} schema "users" do - has_many :links, Philomena.UserLinks.UserLink - has_many :verified_links, Philomena.UserLinks.UserLink, where: [aasm_state: "verified"] - has_many :public_links, Philomena.UserLinks.UserLink, where: [public: true, aasm_state: "verified"] - has_many :galleries, Philomena.Galleries.Gallery, foreign_key: :creator_id - has_many :awards, Philomena.Badges.Award - has_many :unread_notifications, Philomena.Notifications.UnreadNotification + has_many :links, UserLink + has_many :verified_links, UserLink, where: [aasm_state: "verified"] + has_many :public_links, UserLink, where: [public: true, aasm_state: "verified"] + has_many :galleries, Gallery, foreign_key: :creator_id + has_many :awards, Badges.Award + has_many :unread_notifications, UnreadNotification has_many :notifications, through: [:unread_notifications, :notification] - belongs_to :current_filter, Philomena.Filters.Filter - belongs_to :deleted_by_user, Philomena.Users.User + belongs_to :current_filter, Filter + belongs_to :deleted_by_user, User # Authentication field :email, :string diff --git a/mix.exs b/mix.exs index cbfa68d5..d4598d7c 100644 --- a/mix.exs +++ b/mix.exs @@ -58,7 +58,7 @@ defmodule Philomena.MixProject do {:redix, "~> 0.10.2"}, {:bamboo, "~> 1.2"}, {:bamboo_smtp, "~> 1.7"}, - {:remote_ip, "~> 0.1.5"} + {:remote_ip, "~> 0.2.0"} ] end diff --git a/mix.lock b/mix.lock index c310750d..4bc56f6a 100644 --- a/mix.lock +++ b/mix.lock @@ -49,7 +49,7 @@ "qrcode": {:hex, :qrcode, "0.1.5", "551271830515c150f34568345b060c625deb0e6691db2a01b0a6de3aafc93886", [:mix], [], "hexpm"}, "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"}, "redix": {:hex, :redix, "0.10.2", "a9eabf47898aa878650df36194aeb63966d74f5bd69d9caa37babb32dbb93c5d", [:mix], [{:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, - "remote_ip": {:hex, :remote_ip, "0.1.5", "0d8eb8a80387e196b0f48b3e7efb75525d1097cdb0ec70a4c69dd2ce9237c16c", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:inet_cidr, "~> 1.0", [hex: :inet_cidr, repo: "hexpm", optional: false]}, {:plug, "~> 1.2", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "remote_ip": {:hex, :remote_ip, "0.2.0", "6a40b87bc06fb33c71e423e4f2cdc76e45d42326508b4f9aaef6ff576190443d", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:inet_cidr, "~> 1.0", [hex: :inet_cidr, repo: "hexpm", optional: false]}, {:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "retry": {:hex, :retry, "0.13.0", "bb9b2713f70f39337837852337ad280c77662574f4fb852a8386c269f3d734c4", [:mix], [], "hexpm"}, "scrivener": {:hex, :scrivener, "2.7.0", "fa94cdea21fad0649921d8066b1833d18d296217bfdf4a5389a2f45ee857b773", [:mix], [], "hexpm"}, "scrivener_ecto": {:hex, :scrivener_ecto, "2.2.0", "53d5f1ba28f35f17891cf526ee102f8f225b7024d1cdaf8984875467158c9c5e", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:scrivener, "~> 2.4", [hex: :scrivener, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/philomena/image_faves_test.exs b/test/philomena/image_faves_test.exs new file mode 100644 index 00000000..0cd990d2 --- /dev/null +++ b/test/philomena/image_faves_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.ImageFavesTest do + use Philomena.DataCase + + alias Philomena.ImageFaves + + describe "image_faves" do + alias Philomena.ImageFaves.ImageFave + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def image_fave_fixture(attrs \\ %{}) do + {:ok, image_fave} = + attrs + |> Enum.into(@valid_attrs) + |> ImageFaves.create_image_fave() + + image_fave + end + + test "list_image_faves/0 returns all image_faves" do + image_fave = image_fave_fixture() + assert ImageFaves.list_image_faves() == [image_fave] + end + + test "get_image_fave!/1 returns the image_fave with given id" do + image_fave = image_fave_fixture() + assert ImageFaves.get_image_fave!(image_fave.id) == image_fave + end + + test "create_image_fave/1 with valid data creates a image_fave" do + assert {:ok, %ImageFave{} = image_fave} = ImageFaves.create_image_fave(@valid_attrs) + end + + test "create_image_fave/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = ImageFaves.create_image_fave(@invalid_attrs) + end + + test "update_image_fave/2 with valid data updates the image_fave" do + image_fave = image_fave_fixture() + assert {:ok, %ImageFave{} = image_fave} = ImageFaves.update_image_fave(image_fave, @update_attrs) + end + + test "update_image_fave/2 with invalid data returns error changeset" do + image_fave = image_fave_fixture() + assert {:error, %Ecto.Changeset{}} = ImageFaves.update_image_fave(image_fave, @invalid_attrs) + assert image_fave == ImageFaves.get_image_fave!(image_fave.id) + end + + test "delete_image_fave/1 deletes the image_fave" do + image_fave = image_fave_fixture() + assert {:ok, %ImageFave{}} = ImageFaves.delete_image_fave(image_fave) + assert_raise Ecto.NoResultsError, fn -> ImageFaves.get_image_fave!(image_fave.id) end + end + + test "change_image_fave/1 returns a image_fave changeset" do + image_fave = image_fave_fixture() + assert %Ecto.Changeset{} = ImageFaves.change_image_fave(image_fave) + end + end +end diff --git a/test/philomena/image_features_test.exs b/test/philomena/image_features_test.exs new file mode 100644 index 00000000..c208f497 --- /dev/null +++ b/test/philomena/image_features_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.ImageFeaturesTest do + use Philomena.DataCase + + alias Philomena.ImageFeatures + + describe "image_features" do + alias Philomena.ImageFeatures.ImageFeature + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def image_feature_fixture(attrs \\ %{}) do + {:ok, image_feature} = + attrs + |> Enum.into(@valid_attrs) + |> ImageFeatures.create_image_feature() + + image_feature + end + + test "list_image_features/0 returns all image_features" do + image_feature = image_feature_fixture() + assert ImageFeatures.list_image_features() == [image_feature] + end + + test "get_image_feature!/1 returns the image_feature with given id" do + image_feature = image_feature_fixture() + assert ImageFeatures.get_image_feature!(image_feature.id) == image_feature + end + + test "create_image_feature/1 with valid data creates a image_feature" do + assert {:ok, %ImageFeature{} = image_feature} = ImageFeatures.create_image_feature(@valid_attrs) + end + + test "create_image_feature/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = ImageFeatures.create_image_feature(@invalid_attrs) + end + + test "update_image_feature/2 with valid data updates the image_feature" do + image_feature = image_feature_fixture() + assert {:ok, %ImageFeature{} = image_feature} = ImageFeatures.update_image_feature(image_feature, @update_attrs) + end + + test "update_image_feature/2 with invalid data returns error changeset" do + image_feature = image_feature_fixture() + assert {:error, %Ecto.Changeset{}} = ImageFeatures.update_image_feature(image_feature, @invalid_attrs) + assert image_feature == ImageFeatures.get_image_feature!(image_feature.id) + end + + test "delete_image_feature/1 deletes the image_feature" do + image_feature = image_feature_fixture() + assert {:ok, %ImageFeature{}} = ImageFeatures.delete_image_feature(image_feature) + assert_raise Ecto.NoResultsError, fn -> ImageFeatures.get_image_feature!(image_feature.id) end + end + + test "change_image_feature/1 returns a image_feature changeset" do + image_feature = image_feature_fixture() + assert %Ecto.Changeset{} = ImageFeatures.change_image_feature(image_feature) + end + end +end diff --git a/test/philomena/image_hides_test.exs b/test/philomena/image_hides_test.exs new file mode 100644 index 00000000..77a66b17 --- /dev/null +++ b/test/philomena/image_hides_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.ImageHidesTest do + use Philomena.DataCase + + alias Philomena.ImageHides + + describe "image_hides" do + alias Philomena.ImageHides.ImageHide + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def image_hide_fixture(attrs \\ %{}) do + {:ok, image_hide} = + attrs + |> Enum.into(@valid_attrs) + |> ImageHides.create_image_hide() + + image_hide + end + + test "list_image_hides/0 returns all image_hides" do + image_hide = image_hide_fixture() + assert ImageHides.list_image_hides() == [image_hide] + end + + test "get_image_hide!/1 returns the image_hide with given id" do + image_hide = image_hide_fixture() + assert ImageHides.get_image_hide!(image_hide.id) == image_hide + end + + test "create_image_hide/1 with valid data creates a image_hide" do + assert {:ok, %ImageHide{} = image_hide} = ImageHides.create_image_hide(@valid_attrs) + end + + test "create_image_hide/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = ImageHides.create_image_hide(@invalid_attrs) + end + + test "update_image_hide/2 with valid data updates the image_hide" do + image_hide = image_hide_fixture() + assert {:ok, %ImageHide{} = image_hide} = ImageHides.update_image_hide(image_hide, @update_attrs) + end + + test "update_image_hide/2 with invalid data returns error changeset" do + image_hide = image_hide_fixture() + assert {:error, %Ecto.Changeset{}} = ImageHides.update_image_hide(image_hide, @invalid_attrs) + assert image_hide == ImageHides.get_image_hide!(image_hide.id) + end + + test "delete_image_hide/1 deletes the image_hide" do + image_hide = image_hide_fixture() + assert {:ok, %ImageHide{}} = ImageHides.delete_image_hide(image_hide) + assert_raise Ecto.NoResultsError, fn -> ImageHides.get_image_hide!(image_hide.id) end + end + + test "change_image_hide/1 returns a image_hide changeset" do + image_hide = image_hide_fixture() + assert %Ecto.Changeset{} = ImageHides.change_image_hide(image_hide) + end + end +end diff --git a/test/philomena/image_intensities_test.exs b/test/philomena/image_intensities_test.exs new file mode 100644 index 00000000..f65480ad --- /dev/null +++ b/test/philomena/image_intensities_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.ImageIntensitiesTest do + use Philomena.DataCase + + alias Philomena.ImageIntensities + + describe "image_intensities" do + alias Philomena.ImageIntensities.ImageIntensity + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def image_intensity_fixture(attrs \\ %{}) do + {:ok, image_intensity} = + attrs + |> Enum.into(@valid_attrs) + |> ImageIntensities.create_image_intensity() + + image_intensity + end + + test "list_image_intensities/0 returns all image_intensities" do + image_intensity = image_intensity_fixture() + assert ImageIntensities.list_image_intensities() == [image_intensity] + end + + test "get_image_intensity!/1 returns the image_intensity with given id" do + image_intensity = image_intensity_fixture() + assert ImageIntensities.get_image_intensity!(image_intensity.id) == image_intensity + end + + test "create_image_intensity/1 with valid data creates a image_intensity" do + assert {:ok, %ImageIntensity{} = image_intensity} = ImageIntensities.create_image_intensity(@valid_attrs) + end + + test "create_image_intensity/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = ImageIntensities.create_image_intensity(@invalid_attrs) + end + + test "update_image_intensity/2 with valid data updates the image_intensity" do + image_intensity = image_intensity_fixture() + assert {:ok, %ImageIntensity{} = image_intensity} = ImageIntensities.update_image_intensity(image_intensity, @update_attrs) + end + + test "update_image_intensity/2 with invalid data returns error changeset" do + image_intensity = image_intensity_fixture() + assert {:error, %Ecto.Changeset{}} = ImageIntensities.update_image_intensity(image_intensity, @invalid_attrs) + assert image_intensity == ImageIntensities.get_image_intensity!(image_intensity.id) + end + + test "delete_image_intensity/1 deletes the image_intensity" do + image_intensity = image_intensity_fixture() + assert {:ok, %ImageIntensity{}} = ImageIntensities.delete_image_intensity(image_intensity) + assert_raise Ecto.NoResultsError, fn -> ImageIntensities.get_image_intensity!(image_intensity.id) end + end + + test "change_image_intensity/1 returns a image_intensity changeset" do + image_intensity = image_intensity_fixture() + assert %Ecto.Changeset{} = ImageIntensities.change_image_intensity(image_intensity) + end + end +end diff --git a/test/philomena/image_votes_test.exs b/test/philomena/image_votes_test.exs new file mode 100644 index 00000000..8866840f --- /dev/null +++ b/test/philomena/image_votes_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.ImageVotesTest do + use Philomena.DataCase + + alias Philomena.ImageVotes + + describe "image_votes" do + alias Philomena.ImageVotes.ImageVote + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def image_vote_fixture(attrs \\ %{}) do + {:ok, image_vote} = + attrs + |> Enum.into(@valid_attrs) + |> ImageVotes.create_image_vote() + + image_vote + end + + test "list_image_votes/0 returns all image_votes" do + image_vote = image_vote_fixture() + assert ImageVotes.list_image_votes() == [image_vote] + end + + test "get_image_vote!/1 returns the image_vote with given id" do + image_vote = image_vote_fixture() + assert ImageVotes.get_image_vote!(image_vote.id) == image_vote + end + + test "create_image_vote/1 with valid data creates a image_vote" do + assert {:ok, %ImageVote{} = image_vote} = ImageVotes.create_image_vote(@valid_attrs) + end + + test "create_image_vote/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = ImageVotes.create_image_vote(@invalid_attrs) + end + + test "update_image_vote/2 with valid data updates the image_vote" do + image_vote = image_vote_fixture() + assert {:ok, %ImageVote{} = image_vote} = ImageVotes.update_image_vote(image_vote, @update_attrs) + end + + test "update_image_vote/2 with invalid data returns error changeset" do + image_vote = image_vote_fixture() + assert {:error, %Ecto.Changeset{}} = ImageVotes.update_image_vote(image_vote, @invalid_attrs) + assert image_vote == ImageVotes.get_image_vote!(image_vote.id) + end + + test "delete_image_vote/1 deletes the image_vote" do + image_vote = image_vote_fixture() + assert {:ok, %ImageVote{}} = ImageVotes.delete_image_vote(image_vote) + assert_raise Ecto.NoResultsError, fn -> ImageVotes.get_image_vote!(image_vote.id) end + end + + test "change_image_vote/1 returns a image_vote changeset" do + image_vote = image_vote_fixture() + assert %Ecto.Changeset{} = ImageVotes.change_image_vote(image_vote) + end + end +end diff --git a/test/philomena/source_changes_test.exs b/test/philomena/source_changes_test.exs new file mode 100644 index 00000000..40d0bd38 --- /dev/null +++ b/test/philomena/source_changes_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.SourceChangesTest do + use Philomena.DataCase + + alias Philomena.SourceChanges + + describe "source_changes" do + alias Philomena.SourceChanges.SourceChange + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def source_change_fixture(attrs \\ %{}) do + {:ok, source_change} = + attrs + |> Enum.into(@valid_attrs) + |> SourceChanges.create_source_change() + + source_change + end + + test "list_source_changes/0 returns all source_changes" do + source_change = source_change_fixture() + assert SourceChanges.list_source_changes() == [source_change] + end + + test "get_source_change!/1 returns the source_change with given id" do + source_change = source_change_fixture() + assert SourceChanges.get_source_change!(source_change.id) == source_change + end + + test "create_source_change/1 with valid data creates a source_change" do + assert {:ok, %SourceChange{} = source_change} = SourceChanges.create_source_change(@valid_attrs) + end + + test "create_source_change/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = SourceChanges.create_source_change(@invalid_attrs) + end + + test "update_source_change/2 with valid data updates the source_change" do + source_change = source_change_fixture() + assert {:ok, %SourceChange{} = source_change} = SourceChanges.update_source_change(source_change, @update_attrs) + end + + test "update_source_change/2 with invalid data returns error changeset" do + source_change = source_change_fixture() + assert {:error, %Ecto.Changeset{}} = SourceChanges.update_source_change(source_change, @invalid_attrs) + assert source_change == SourceChanges.get_source_change!(source_change.id) + end + + test "delete_source_change/1 deletes the source_change" do + source_change = source_change_fixture() + assert {:ok, %SourceChange{}} = SourceChanges.delete_source_change(source_change) + assert_raise Ecto.NoResultsError, fn -> SourceChanges.get_source_change!(source_change.id) end + end + + test "change_source_change/1 returns a source_change changeset" do + source_change = source_change_fixture() + assert %Ecto.Changeset{} = SourceChanges.change_source_change(source_change) + end + end +end diff --git a/test/philomena/tag_changes_test.exs b/test/philomena/tag_changes_test.exs new file mode 100644 index 00000000..8473b103 --- /dev/null +++ b/test/philomena/tag_changes_test.exs @@ -0,0 +1,62 @@ +defmodule Philomena.TagChangesTest do + use Philomena.DataCase + + alias Philomena.TagChanges + + describe "tag_changes" do + alias Philomena.TagChanges.TagChange + + @valid_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + def tag_change_fixture(attrs \\ %{}) do + {:ok, tag_change} = + attrs + |> Enum.into(@valid_attrs) + |> TagChanges.create_tag_change() + + tag_change + end + + test "list_tag_changes/0 returns all tag_changes" do + tag_change = tag_change_fixture() + assert TagChanges.list_tag_changes() == [tag_change] + end + + test "get_tag_change!/1 returns the tag_change with given id" do + tag_change = tag_change_fixture() + assert TagChanges.get_tag_change!(tag_change.id) == tag_change + end + + test "create_tag_change/1 with valid data creates a tag_change" do + assert {:ok, %TagChange{} = tag_change} = TagChanges.create_tag_change(@valid_attrs) + end + + test "create_tag_change/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = TagChanges.create_tag_change(@invalid_attrs) + end + + test "update_tag_change/2 with valid data updates the tag_change" do + tag_change = tag_change_fixture() + assert {:ok, %TagChange{} = tag_change} = TagChanges.update_tag_change(tag_change, @update_attrs) + end + + test "update_tag_change/2 with invalid data returns error changeset" do + tag_change = tag_change_fixture() + assert {:error, %Ecto.Changeset{}} = TagChanges.update_tag_change(tag_change, @invalid_attrs) + assert tag_change == TagChanges.get_tag_change!(tag_change.id) + end + + test "delete_tag_change/1 deletes the tag_change" do + tag_change = tag_change_fixture() + assert {:ok, %TagChange{}} = TagChanges.delete_tag_change(tag_change) + assert_raise Ecto.NoResultsError, fn -> TagChanges.get_tag_change!(tag_change.id) end + end + + test "change_tag_change/1 returns a tag_change changeset" do + tag_change = tag_change_fixture() + assert %Ecto.Changeset{} = TagChanges.change_tag_change(tag_change) + end + end +end