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

Commit 151f4e7

Browse files
committed
refactor: naming
1 parent 26b2589 commit 151f4e7

File tree

13 files changed

+266
-377
lines changed

13 files changed

+266
-377
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 mirror_community(thread, article_id, community_id), to: ArticleCommunity
113-
defdelegate unmirror_community(thread, article_id, community_id), to: ArticleCommunity
112+
defdelegate mirror_article(thread, article_id, community_id), to: ArticleCommunity
113+
defdelegate unmirror_article(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: 4 additions & 4 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 mirror_community(thread, article_id, community_id) do
110+
def mirror_article(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,14 +121,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
121121
@doc """
122122
unmirror article to a community
123123
"""
124-
def unmirror_community(thread, article_id, community_id) do
124+
def unmirror_article(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]),
128128
{:ok, community} <- ORM.find(Community, community_id) do
129129
case article.original_community.id == community.id do
130130
true ->
131-
raise_error(:mirror_community, "can not unmirror original_community")
131+
raise_error(:mirror_article, "can not unmirror original_community")
132132

133133
false ->
134134
article
@@ -153,7 +153,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
153153
|> Ecto.Changeset.put_change(:original_community_id, community.id)
154154
|> Repo.update()
155155
end)
156-
|> Multi.run(:unmirror_community, fn _, %{change_original_community: article} ->
156+
|> Multi.run(:unmirror_article, fn _, %{change_original_community: article} ->
157157
article
158158
|> Ecto.Changeset.change()
159159
|> Ecto.Changeset.put_assoc(:communities, article.communities -- [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(:mirror_community, fn _, %{create_article: article} ->
136-
ArticleCommunity.mirror_community(thread, article.id, community.id)
135+
|> Multi.run(:mirror_article, fn _, %{create_article: article} ->
136+
ArticleCommunity.mirror_article(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, :mirror_community, _result, _steps}) do
371+
defp create_content_result({:error, :mirror_article, _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 mirror_community(_root, ~m(thread id community_id)a, _info) do
294-
CMS.mirror_community(thread, id, community_id)
293+
def mirror_article(_root, ~m(thread id community_id)a, _info) do
294+
CMS.mirror_article(thread, id, community_id)
295295
end
296296

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

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

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,37 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
108108
resolve(&R.CMS.unset_tag/3)
109109
end
110110

111-
# TODO: use community loader
112-
field :mirror_community, :community do
111+
@desc "mirror article to other community"
112+
field :mirror_article, :article 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)
118118
middleware(M.Passport, claim: "cms->t?.community.mirror")
119-
resolve(&R.CMS.mirror_community/3)
119+
resolve(&R.CMS.mirror_article/3)
120120
end
121121

122-
# TODO: can't not unset the oldest community
123-
field :unmirror_community, :community do
122+
@desc "unmirror article to other community"
123+
field :unmirror_article, :article 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)
129129
middleware(M.Passport, claim: "cms->t?.community.unmirror")
130-
resolve(&R.CMS.unmirror_community/3)
130+
resolve(&R.CMS.unmirror_article/3)
131131
end
132+
133+
# @desc "move article to other community"
134+
# field :move_article, :article do
135+
# arg(:id, non_null(:id))
136+
# arg(:community_id, non_null(:id))
137+
# arg(:thread, :thread, default_value: :post)
138+
139+
# middleware(M.Authorize, :login)
140+
# middleware(M.Passport, claim: "cms->t?.community.mirror")
141+
# resolve(&R.CMS.mirror_article/3)
142+
# end
132143
end
133144
end

lib/helper/error_code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ defmodule Helper.ErrorCode do
4646
def ecode(:already_collected_in_folder), do: @article_base + 2
4747
def ecode(:delete_no_empty_collect_folder), do: @article_base + 3
4848
def ecode(:private_collect_folder), do: @article_base + 4
49-
def ecode(:mirror_community), do: @article_base + 5
49+
def ecode(:mirror_article), do: @article_base + 5
5050

5151
def ecode, do: @default_base
5252
# def ecode(_), do: @default_base

test/groupher_server/cms/article_community/job_test.exs

Lines changed: 8 additions & 8 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.mirror_community(:job, job.id, community2.id)
48+
{:ok, _} = CMS.mirror_article(: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.mirror_community(:job, job.id, community2.id)
60-
{:ok, _} = CMS.mirror_community(:job, job.id, community3.id)
59+
{:ok, _} = CMS.mirror_article(:job, job.id, community2.id)
60+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:job, job.id, community3.id)
65+
{:ok, _} = CMS.unmirror_article(:job, job.id, community3.id)
6666
{:ok, job} = ORM.find(CMS.Job, job.id, preload: :communities)
6767
assert job.communities |> length == 2
6868

@@ -72,14 +72,14 @@ 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.mirror_community(:job, job.id, community2.id)
76-
{:ok, _} = CMS.mirror_community(:job, job.id, community3.id)
75+
{:ok, _} = CMS.mirror_article(:job, job.id, community2.id)
76+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:job, job.id, community.id)
82-
assert reason |> is_error?(:mirror_community)
81+
{:error, reason} = CMS.unmirror_article(:job, job.id, community.id)
82+
assert reason |> is_error?(:mirror_article)
8383
end
8484
end
8585
end

test/groupher_server/cms/article_community/post_test.exs

Lines changed: 8 additions & 8 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.mirror_community(:post, post.id, community2.id)
48+
{:ok, _} = CMS.mirror_article(: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.mirror_community(:post, post.id, community2.id)
60-
{:ok, _} = CMS.mirror_community(:post, post.id, community3.id)
59+
{:ok, _} = CMS.mirror_article(:post, post.id, community2.id)
60+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:post, post.id, community3.id)
65+
{:ok, _} = CMS.unmirror_article(:post, post.id, community3.id)
6666
{:ok, post} = ORM.find(CMS.Post, post.id, preload: :communities)
6767
assert post.communities |> length == 2
6868

@@ -72,14 +72,14 @@ 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.mirror_community(:post, post.id, community2.id)
76-
{:ok, _} = CMS.mirror_community(:post, post.id, community3.id)
75+
{:ok, _} = CMS.mirror_article(:post, post.id, community2.id)
76+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:post, post.id, community.id)
82-
assert reason |> is_error?(:mirror_community)
81+
{:error, reason} = CMS.unmirror_article(:post, post.id, community.id)
82+
assert reason |> is_error?(:mirror_article)
8383
end
8484
end
8585
end

test/groupher_server/cms/article_community/repo_test.exs

Lines changed: 8 additions & 8 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.mirror_community(:repo, repo.id, community2.id)
48+
{:ok, _} = CMS.mirror_article(: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.mirror_community(:repo, repo.id, community2.id)
60-
{:ok, _} = CMS.mirror_community(:repo, repo.id, community3.id)
59+
{:ok, _} = CMS.mirror_article(:repo, repo.id, community2.id)
60+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:repo, repo.id, community3.id)
65+
{:ok, _} = CMS.unmirror_article(:repo, repo.id, community3.id)
6666
{:ok, repo} = ORM.find(CMS.Repo, repo.id, preload: :communities)
6767
assert repo.communities |> length == 2
6868

@@ -72,14 +72,14 @@ 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.mirror_community(:repo, repo.id, community2.id)
76-
{:ok, _} = CMS.mirror_community(:repo, repo.id, community3.id)
75+
{:ok, _} = CMS.mirror_article(:repo, repo.id, community2.id)
76+
{:ok, _} = CMS.mirror_article(: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.unmirror_community(:repo, repo.id, community.id)
82-
assert reason |> is_error?(:mirror_community)
81+
{:error, reason} = CMS.unmirror_article(:repo, repo.id, community.id)
82+
assert reason |> is_error?(:mirror_article)
8383
end
8484
end
8585
end

0 commit comments

Comments
 (0)