Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit c1bd515

Browse files
committed
refactor(cms-macros): unused emotion config
1 parent 682a984 commit c1bd515

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

config/config.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ config :groupher_server, :customization,
6161
sidebar_communities_index: %{}
6262

6363
config :groupher_server, :article,
64-
emotionable_threads: [:post, :job],
6564
# NOTE: if you want to add/remove emotion, just edit the list below
6665
# and migrate the field to table "articles_users_emotions"
6766
supported_emotions: [

lib/groupher_server/cms/article_comment.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ defmodule GroupherServer.CMS.ArticleComment do
7878
has_many(:upvotes, {"articles_comments_upvotes", ArticleCommentUpvote})
7979

8080
article_belongs_to()
81-
8281
timestamps(type: :utc_datetime)
8382
end
8483

lib/groupher_server/cms/article_user_emotion.ex

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ defmodule GroupherServer.CMS.ArticleUserEmotion do
2323
import Ecto.Changeset
2424
import GroupherServer.CMS.ArticleUserEmotion.Macros
2525
import Helper.Utils, only: [get_config: 2]
26+
import GroupherServer.CMS.Helper.Macros
27+
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]
2628

2729
alias GroupherServer.{Accounts, CMS}
28-
alias CMS.{Post, Job}
2930

3031
@supported_emotions get_config(:article, :supported_emotions)
31-
@supported_threads get_config(:article, :emotionable_threads)
32+
@article_threads CMS.Community.article_threads()
3233

3334
@required_fields ~w(user_id recived_user_id)a
34-
@optional_fields Enum.map(@supported_threads, &:"#{&1}_id") ++
35+
@optional_fields Enum.map(@article_threads, &:"#{&1}_id") ++
3536
Enum.map(@supported_emotions, &:"#{&1}")
3637

3738
@type t :: %ArticleUserEmotion{}
3839
schema "articles_users_emotions" do
39-
belongs_to(:post, Post, foreign_key: :post_id)
40-
belongs_to(:job, Job, foreign_key: :job_id)
4140
belongs_to(:recived_user, Accounts.User, foreign_key: :recived_user_id)
4241
belongs_to(:user, Accounts.User, foreign_key: :user_id)
4342

4443
emotion_fields()
44+
article_belongs_to()
4545
timestamps(type: :utc_datetime)
4646
end
4747

@@ -50,19 +50,17 @@ defmodule GroupherServer.CMS.ArticleUserEmotion do
5050
struct
5151
|> cast(attrs, @required_fields ++ @optional_fields)
5252
|> validate_required(@required_fields)
53-
# |> foreign_key_constraint(:post_id)
54-
# |> foreign_key_constraint(:job_id)
5553
|> foreign_key_constraint(:user_id)
5654
|> foreign_key_constraint(:recived_user_id)
55+
|> articles_foreign_key_constraint
5756
end
5857

5958
def update_changeset(%ArticleUserEmotion{} = struct, attrs) do
6059
struct
6160
|> cast(attrs, @required_fields ++ @optional_fields)
6261
|> validate_required(@required_fields)
63-
# |> foreign_key_constraint(:post_id)
64-
# |> foreign_key_constraint(:job_id)
6562
|> foreign_key_constraint(:user_id)
6663
|> foreign_key_constraint(:recived_user_id)
64+
|> articles_foreign_key_constraint
6765
end
6866
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule GroupherServer.Repo.Migrations.AddRepoSupportInEmotion do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:articles_users_emotions) do
6+
add(:repo_id, references(:cms_repos, on_delete: :delete_all))
7+
end
8+
end
9+
end

test/groupher_server/cms/comments/post_comment_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
350350
assert results.total_count == total_count + 1
351351
end
352352

353+
@tag :wip2
353354
test "paged article comments folded flag should be false", ~m(user post)a do
354355
total_count = 30
355356
page_number = 1

0 commit comments

Comments
 (0)