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

Commit 26b2589

Browse files
committed
refactor: naming
1 parent 902e0e4 commit 26b2589

File tree

11 files changed

+62
-60
lines changed

11 files changed

+62
-60
lines changed

cover/excoveralls.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/groupher_server/cms/cms.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ defmodule GroupherServer.CMS do
109109
defdelegate set_tag(thread, tag, content_id), to: ArticleCommunity
110110
defdelegate unset_tag(thread, tag, content_id), to: ArticleCommunity
111111
# >> community: set / unset
112-
defdelegate set_community(thread, article_id, community_id), to: ArticleCommunity
113-
defdelegate unset_community(thread, article_id, community_id), to: ArticleCommunity
112+
defdelegate mirror_community(thread, article_id, community_id), to: ArticleCommunity
113+
defdelegate unmirror_community(thread, article_id, community_id), to: ArticleCommunity
114114
defdelegate move_article(thread, article_id, community_id), to: ArticleCommunity
115115

116116
defdelegate emotion_to_article(thread, article_id, args, user), to: ArticleEmotion

lib/groupher_server/cms/delegates/article_community.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
107107
@doc """
108108
mirror article to other community
109109
"""
110-
def set_community(thread, article_id, community_id) do
110+
def mirror_community(thread, article_id, community_id) do
111111
with {:ok, info} <- match(thread),
112112
{:ok, article} <- ORM.find(info.model, article_id, preload: :communities),
113113
{:ok, community} <- ORM.find(Community, community_id) do
@@ -121,7 +121,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
121121
@doc """
122122
unmirror article to a community
123123
"""
124-
def unset_community(thread, article_id, community_id) do
124+
def unmirror_community(thread, article_id, community_id) do
125125
with {:ok, info} <- match(thread),
126126
{:ok, article} <-
127127
ORM.find(info.model, article_id, preload: [:communities, :original_community]),

lib/groupher_server/cms/delegates/article_curd.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
132132
|> Multi.run(:create_article, fn _, _ ->
133133
do_create_article(action.target, attrs, author, community)
134134
end)
135-
|> Multi.run(:set_community, fn _, %{create_article: article} ->
136-
ArticleCommunity.set_community(thread, article.id, community.id)
135+
|> Multi.run(:mirror_community, fn _, %{create_article: article} ->
136+
ArticleCommunity.mirror_community(thread, article.id, community.id)
137137
end)
138138
|> Multi.run(:set_community_flag, fn _, %{create_article: article} ->
139139
exec_set_community_flag(community, article, action)
@@ -368,7 +368,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
368368
{:error, [message: "create cms content author", code: ecode(:create_fails)]}
369369
end
370370

371-
defp create_content_result({:error, :set_community, _result, _steps}) do
371+
defp create_content_result({:error, :mirror_community, _result, _steps}) do
372372
{:error, [message: "set community", code: ecode(:create_fails)]}
373373
end
374374

lib/groupher_server_web/resolvers/cms_resolver.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ defmodule GroupherServerWeb.Resolvers.CMS do
290290

291291
def community_subscribers(_root, _args, _info), do: {:error, "invalid args"}
292292

293-
def set_community(_root, ~m(thread id community_id)a, _info) do
294-
CMS.set_community(thread, id, community_id)
293+
def mirror_community(_root, ~m(thread id community_id)a, _info) do
294+
CMS.mirror_community(thread, id, community_id)
295295
end
296296

297-
def unset_community(_root, ~m(thread id community_id)a, _info) do
298-
CMS.unset_community(thread, id, community_id)
297+
def unmirror_community(_root, ~m(thread id community_id)a, _info) do
298+
CMS.unmirror_community(thread, id, community_id)
299299
end
300300

301301
# #######################

lib/groupher_server_web/schema/cms/mutations/operation.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,25 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
109109
end
110110

111111
# TODO: use community loader
112-
field :set_community, :community do
112+
field :mirror_community, :community do
113113
arg(:id, non_null(:id))
114114
arg(:community_id, non_null(:id))
115115
arg(:thread, :thread, default_value: :post)
116116

117117
middleware(M.Authorize, :login)
118-
middleware(M.Passport, claim: "cms->t?.community.set")
119-
resolve(&R.CMS.set_community/3)
118+
middleware(M.Passport, claim: "cms->t?.community.mirror")
119+
resolve(&R.CMS.mirror_community/3)
120120
end
121121

122122
# TODO: can't not unset the oldest community
123-
field :unset_community, :community do
123+
field :unmirror_community, :community do
124124
arg(:id, non_null(:id))
125125
arg(:community_id, non_null(:id))
126126
arg(:thread, :thread, default_value: :post)
127127

128128
middleware(M.Authorize, :login)
129-
middleware(M.Passport, claim: "cms->t?.community.unset")
130-
resolve(&R.CMS.unset_community/3)
129+
middleware(M.Passport, claim: "cms->t?.community.unmirror")
130+
resolve(&R.CMS.unmirror_community/3)
131131
end
132132
end
133133
end

lib/helper/certification.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ defmodule Helper.Certification do
5151
"category.set",
5252
"category.unset",
5353
"thread.create",
54-
"post.community.set",
55-
"post.community.unset",
56-
"job.community.set",
57-
"job.community.unset",
54+
"post.community.mirror",
55+
"post.community.unmirror",
56+
"job.community.mirror",
57+
"job.community.unmirror",
5858
# flag on content
5959
"post.pin",
6060
"post.undo_pin",

test/groupher_server/cms/article_community/job_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Job do
4545

4646
assert not is_nil(Enum.find(job.communities, &(&1.id == community.id)))
4747

48-
{:ok, _} = CMS.set_community(:job, job.id, community2.id)
48+
{:ok, _} = CMS.mirror_community(:job, job.id, community2.id)
4949

5050
{:ok, job} = ORM.find(CMS.Job, job.id, preload: :communities)
5151
assert job.communities |> length == 2
@@ -56,13 +56,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Job do
5656
test "job can be unmirror from community",
5757
~m(user community community2 community3 job_attrs)a do
5858
{:ok, job} = CMS.create_article(community, :job, job_attrs, user)
59-
{:ok, _} = CMS.set_community(:job, job.id, community2.id)
60-
{:ok, _} = CMS.set_community(:job, job.id, community3.id)
59+
{:ok, _} = CMS.mirror_community(:job, job.id, community2.id)
60+
{:ok, _} = CMS.mirror_community(:job, job.id, community3.id)
6161

6262
{:ok, job} = ORM.find(CMS.Job, job.id, preload: :communities)
6363
assert job.communities |> length == 3
6464

65-
{:ok, _} = CMS.unset_community(:job, job.id, community3.id)
65+
{:ok, _} = CMS.unmirror_community(:job, job.id, community3.id)
6666
{:ok, job} = ORM.find(CMS.Job, job.id, preload: :communities)
6767
assert job.communities |> length == 2
6868

@@ -72,13 +72,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Job do
7272
test "job can not unmirror from original community",
7373
~m(user community community2 community3 job_attrs)a do
7474
{:ok, job} = CMS.create_article(community, :job, job_attrs, user)
75-
{:ok, _} = CMS.set_community(:job, job.id, community2.id)
76-
{:ok, _} = CMS.set_community(:job, job.id, community3.id)
75+
{:ok, _} = CMS.mirror_community(:job, job.id, community2.id)
76+
{:ok, _} = CMS.mirror_community(:job, job.id, community3.id)
7777

7878
{:ok, job} = ORM.find(CMS.Job, job.id, preload: :communities)
7979
assert job.communities |> length == 3
8080

81-
{:error, reason} = CMS.unset_community(:job, job.id, community.id)
81+
{:error, reason} = CMS.unmirror_community(:job, job.id, community.id)
8282
assert reason |> is_error?(:mirror_community)
8383
end
8484
end

test/groupher_server/cms/article_community/post_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Post do
4545

4646
assert not is_nil(Enum.find(post.communities, &(&1.id == community.id)))
4747

48-
{:ok, _} = CMS.set_community(:post, post.id, community2.id)
48+
{:ok, _} = CMS.mirror_community(:post, post.id, community2.id)
4949

5050
{:ok, post} = ORM.find(CMS.Post, post.id, preload: :communities)
5151
assert post.communities |> length == 2
@@ -56,13 +56,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Post do
5656
test "post can be unmirror from community",
5757
~m(user community community2 community3 post_attrs)a do
5858
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
59-
{:ok, _} = CMS.set_community(:post, post.id, community2.id)
60-
{:ok, _} = CMS.set_community(:post, post.id, community3.id)
59+
{:ok, _} = CMS.mirror_community(:post, post.id, community2.id)
60+
{:ok, _} = CMS.mirror_community(:post, post.id, community3.id)
6161

6262
{:ok, post} = ORM.find(CMS.Post, post.id, preload: :communities)
6363
assert post.communities |> length == 3
6464

65-
{:ok, _} = CMS.unset_community(:post, post.id, community3.id)
65+
{:ok, _} = CMS.unmirror_community(:post, post.id, community3.id)
6666
{:ok, post} = ORM.find(CMS.Post, post.id, preload: :communities)
6767
assert post.communities |> length == 2
6868

@@ -72,13 +72,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Post do
7272
test "post can not unmirror from original community",
7373
~m(user community community2 community3 post_attrs)a do
7474
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
75-
{:ok, _} = CMS.set_community(:post, post.id, community2.id)
76-
{:ok, _} = CMS.set_community(:post, post.id, community3.id)
75+
{:ok, _} = CMS.mirror_community(:post, post.id, community2.id)
76+
{:ok, _} = CMS.mirror_community(:post, post.id, community3.id)
7777

7878
{:ok, post} = ORM.find(CMS.Post, post.id, preload: :communities)
7979
assert post.communities |> length == 3
8080

81-
{:error, reason} = CMS.unset_community(:post, post.id, community.id)
81+
{:error, reason} = CMS.unmirror_community(:post, post.id, community.id)
8282
assert reason |> is_error?(:mirror_community)
8383
end
8484
end

test/groupher_server/cms/article_community/repo_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Repo do
4545

4646
assert not is_nil(Enum.find(repo.communities, &(&1.id == community.id)))
4747

48-
{:ok, _} = CMS.set_community(:repo, repo.id, community2.id)
48+
{:ok, _} = CMS.mirror_community(:repo, repo.id, community2.id)
4949

5050
{:ok, repo} = ORM.find(CMS.Repo, repo.id, preload: :communities)
5151
assert repo.communities |> length == 2
@@ -56,13 +56,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Repo do
5656
test "repo can be unmirror from community",
5757
~m(user community community2 community3 repo_attrs)a do
5858
{:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user)
59-
{:ok, _} = CMS.set_community(:repo, repo.id, community2.id)
60-
{:ok, _} = CMS.set_community(:repo, repo.id, community3.id)
59+
{:ok, _} = CMS.mirror_community(:repo, repo.id, community2.id)
60+
{:ok, _} = CMS.mirror_community(:repo, repo.id, community3.id)
6161

6262
{:ok, repo} = ORM.find(CMS.Repo, repo.id, preload: :communities)
6363
assert repo.communities |> length == 3
6464

65-
{:ok, _} = CMS.unset_community(:repo, repo.id, community3.id)
65+
{:ok, _} = CMS.unmirror_community(:repo, repo.id, community3.id)
6666
{:ok, repo} = ORM.find(CMS.Repo, repo.id, preload: :communities)
6767
assert repo.communities |> length == 2
6868

@@ -72,13 +72,13 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Repo do
7272
test "repo can not unmirror from original community",
7373
~m(user community community2 community3 repo_attrs)a do
7474
{:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user)
75-
{:ok, _} = CMS.set_community(:repo, repo.id, community2.id)
76-
{:ok, _} = CMS.set_community(:repo, repo.id, community3.id)
75+
{:ok, _} = CMS.mirror_community(:repo, repo.id, community2.id)
76+
{:ok, _} = CMS.mirror_community(:repo, repo.id, community3.id)
7777

7878
{:ok, repo} = ORM.find(CMS.Repo, repo.id, preload: :communities)
7979
assert repo.communities |> length == 3
8080

81-
{:error, reason} = CMS.unset_community(:repo, repo.id, community.id)
81+
{:error, reason} = CMS.unmirror_community(:repo, repo.id, community.id)
8282
assert reason |> is_error?(:mirror_community)
8383
end
8484
end

0 commit comments

Comments
 (0)