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

Commit ed7d00b

Browse files
committed
refactor(article-comment): wip
1 parent 8469d02 commit ed7d00b

File tree

12 files changed

+630
-49
lines changed

12 files changed

+630
-49
lines changed

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
7979
{:ok, T.paged_users()}
8080
def list_article_comments_participators(thread, article_id, filters) do
8181
%{page: page, size: size} = filters
82-
8382
with {:ok, thread_query} <- match(thread, :query, article_id) do
8483
ArticleComment
8584
|> where(^thread_query)

lib/groupher_server_web/schema/cms/cms_types.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
4444
field(:communities, list_of(:community), resolve: dataloader(CMS, :communities))
4545

4646
field(:meta, :article_meta)
47-
field(:article_comments_participators, list_of(:user))
48-
field(:article_comments_participators_count, :integer)
4947

5048
field :comments, list_of(:comment) do
5149
arg(:filter, :members_filter)
@@ -69,6 +67,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
6967
end)
7068
end
7169

70+
article_comments_fields()
7271
viewer_has_state_fields()
7372
# upvoted_count
7473
# collected_count
@@ -99,6 +98,8 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
9998
field(:origial_community, :community, resolve: dataloader(CMS, :origial_community))
10099
field(:communities, list_of(:community), resolve: dataloader(CMS, :communities))
101100

101+
field(:meta, :article_meta)
102+
102103
field(:salary, :string)
103104
field(:exp, :string)
104105
field(:education, :string)
@@ -108,8 +109,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
108109

109110
# comments_count
110111
# comments_participators
111-
comments_counter_fields(:job)
112-
112+
article_comments_fields()
113113
viewer_has_state_fields()
114114
timestamp_fields()
115115
end
@@ -154,7 +154,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
154154
viewer_has_state_fields()
155155
# comments_count
156156
# comments_participators
157-
comments_counter_fields(:repo)
158157

159158
timestamp_fields()
160159
end

lib/groupher_server_web/schema/utils/helper.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ defmodule GroupherServerWeb.Schema.Utils.Helper do
191191
end
192192
end
193193

194+
defmacro article_comments_fields do
195+
quote do
196+
field(:article_comments_participators, list_of(:user))
197+
field(:article_comments_participators_count, :integer)
198+
field(:article_comments_count, :integer)
199+
end
200+
end
201+
194202
defmacro comments_counter_fields(thread) do
195203
quote do
196204
# @dec "total comments of the post"

test/groupher_server/cms/comments/job_comment_emotions_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
7676
assert @default_emotions == emotions
7777
end
7878

79-
@tag :wip2
79+
@tag :wip3
8080
test "can make emotion to comment", ~m(job user user2)a do
8181
parent_content = "parent comment"
8282
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
9191
assert user_exist_in?(user2, emotions.latest_downvote_users)
9292
end
9393

94-
@tag :wip2
94+
@tag :wip3
9595
test "can undo emotion to comment", ~m(job user user2)a do
9696
parent_content = "parent comment"
9797
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
114114
assert not user_exist_in?(user2, emotions.latest_downvote_users)
115115
end
116116

117-
@tag :wip2
117+
@tag :wip3
118118
test "same user make same emotion to same comment.", ~m(job user)a do
119119
parent_content = "parent comment"
120120
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
128128
assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users)
129129
end
130130

131-
@tag :wip2
131+
@tag :wip3
132132
test "same user same emotion to same comment only have one user_emotion record",
133133
~m(job user)a do
134134
parent_content = "parent comment"
@@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
152152
assert record.heart
153153
end
154154

155-
@tag :wip2
155+
@tag :wip3
156156
test "different user can make same emotions on same comment", ~m(job user user2 user3)a do
157157
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
158158

test/groupher_server/cms/comments/job_comment_replies_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
6464
assert exist_in?(replyed_comment_2, parent_comment.replies)
6565
end
6666

67-
@tag :wip2
67+
@tag :wip3
6868
test "reply to reply inside a comment should belong same parent comment",
6969
~m(job user user2)a do
7070
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
9090
assert replyed_comment_3.reply_to_id == replyed_comment_2.id
9191
end
9292

93-
@tag :wip2
93+
@tag :wip3
9494
test "reply to reply inside a comment should have is_reply_to_others flag in meta",
9595
~m(job user user2)a do
9696
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
110110
assert replyed_comment_3.meta.is_reply_to_others
111111
end
112112

113-
@tag :wip2
113+
@tag :wip3
114114
test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do
115115
total_reply_count = @max_parent_replies_count + 1
116116

test/groupher_server/cms/comments/post_comment_emotions_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
7676
assert @default_emotions == emotions
7777
end
7878

79-
@tag :wip2
79+
@tag :wip3
8080
test "can make emotion to comment", ~m(post user user2)a do
8181
parent_content = "parent comment"
8282
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
9191
assert user_exist_in?(user2, emotions.latest_downvote_users)
9292
end
9393

94-
@tag :wip2
94+
@tag :wip3
9595
test "can undo emotion to comment", ~m(post user user2)a do
9696
parent_content = "parent comment"
9797
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
114114
assert not user_exist_in?(user2, emotions.latest_downvote_users)
115115
end
116116

117-
@tag :wip2
117+
@tag :wip3
118118
test "same user make same emotion to same comment.", ~m(post user)a do
119119
parent_content = "parent comment"
120120
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
128128
assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users)
129129
end
130130

131-
@tag :wip2
131+
@tag :wip3
132132
test "same user same emotion to same comment only have one user_emotion record",
133133
~m(post user)a do
134134
parent_content = "parent comment"
@@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
152152
assert record.heart
153153
end
154154

155-
@tag :wip2
155+
@tag :wip3
156156
test "different user can make same emotions on same comment", ~m(post user user2 user3)a do
157157
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user)
158158

test/groupher_server/cms/comments/post_comment_replies_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do
6464
assert exist_in?(replyed_comment_2, parent_comment.replies)
6565
end
6666

67-
@tag :wip2
67+
@tag :wip3
6868
test "reply to reply inside a comment should belong same parent comment",
6969
~m(post user user2)a do
7070
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user)
@@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do
9090
assert replyed_comment_3.reply_to_id == replyed_comment_2.id
9191
end
9292

93-
@tag :wip2
93+
@tag :wip3
9494
test "reply to reply inside a comment should have is_reply_to_others flag in meta",
9595
~m(post user user2)a do
9696
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user)
@@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do
110110
assert replyed_comment_3.meta.is_reply_to_others
111111
end
112112

113-
@tag :wip2
113+
@tag :wip3
114114
test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do
115115
total_reply_count = @max_parent_replies_count + 1
116116

test/groupher_server_web/mutation/cms/article_comment_test.exs renamed to test/groupher_server_web/mutation/cms/comments/post_comment_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule GroupherServer.Test.Mutation.ArticleComment do
1+
defmodule GroupherServer.Test.Mutation.Comments.PostComment do
22
use GroupherServer.TestTools
33

44
alias GroupherServer.CMS
@@ -130,7 +130,7 @@ defmodule GroupherServer.Test.Mutation.ArticleComment do
130130
}
131131
}
132132
"""
133-
@tag :wip2
133+
@tag :wip3
134134
test "login user can undo emotion to a comment", ~m(post user owner_conn)a do
135135
{:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user)
136136
{:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user)

0 commit comments

Comments
 (0)