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

Commit 7a94f57

Browse files
committed
refactor(tag): rm unnecesasary community arg passed down
1 parent 5ebace6 commit 7a94f57

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

lib/mastani_server/cms/cms.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ defmodule MastaniServer.CMS do
9292
# defdelegate undo_pin_content(queryable, community_id, thread), to: ArticleOperation
9393

9494
# >> tag: set / unset
95-
defdelegate set_tag(community, thread, tag, content_id), to: ArticleOperation
95+
defdelegate set_tag(thread, tag, content_id), to: ArticleOperation
9696
defdelegate unset_tag(thread, tag, content_id), to: ArticleOperation
9797
defdelegate set_refined_tag(community, thread, topic, content_id), to: ArticleOperation
9898
defdelegate set_refined_tag(community, thread, content_id), to: ArticleOperation

lib/mastani_server/cms/delegates/article_curd.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
107107
end)
108108
|> Multi.run(:set_tag, fn _, %{add_content_author: content} ->
109109
case attrs |> Map.has_key?(:tags) do
110-
true -> set_tags(community, thread, content.id, attrs.tags)
110+
true -> set_tags(thread, content.id, attrs.tags)
111111
false -> {:ok, :pass}
112112
end
113113
end)
@@ -422,10 +422,10 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
422422
{:error, [message: "log action", code: ecode(:create_fails)]}
423423
end
424424

425-
defp set_tags(community, thread, content_id, tags) do
425+
defp set_tags(thread, content_id, tags) do
426426
try do
427427
Enum.each(tags, fn tag ->
428-
{:ok, _} = ArticleOperation.set_tag(community, thread, %Tag{id: tag.id}, content_id)
428+
{:ok, _} = ArticleOperation.set_tag(thread, %Tag{id: tag.id}, content_id)
429429
end)
430430

431431
{:ok, "psss"}

lib/mastani_server/cms/delegates/article_operation.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
155155
refined tag can't set by this func, use set_refined_tag instead
156156
"""
157157
# check community first
158-
def set_tag(%Community{id: _communitId}, thread, %Tag{id: tag_id}, content_id) do
158+
def set_tag(thread, %Tag{id: tag_id}, content_id) do
159159
with {:ok, action} <- match_action(thread, :tag),
160160
{:ok, content} <- ORM.find(action.target, content_id, preload: :tags),
161161
{:ok, tag} <- ORM.find(action.reactor, tag_id) do

lib/mastani_server/cms/delegates/community_curd.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ defmodule MastaniServer.CMS.Delegate.CommunityCURD do
103103
|> done()
104104
end
105105

106+
@doc """
107+
get all paged tags
108+
"""
109+
def get_tags(%{page: page, size: size} = filter) do
110+
Tag
111+
|> QueryBuilder.filter_pack(filter)
112+
|> ORM.paginater(~m(page size)a)
113+
|> done()
114+
end
115+
106116
@doc """
107117
get tags belongs to a community / thread
108118
"""
@@ -159,16 +169,6 @@ defmodule MastaniServer.CMS.Delegate.CommunityCURD do
159169
|> done()
160170
end
161171

162-
@doc """
163-
get all paged tags
164-
"""
165-
def get_tags(%{page: page, size: size} = filter) do
166-
Tag
167-
|> QueryBuilder.filter_pack(filter)
168-
|> ORM.paginater(~m(page size)a)
169-
|> done()
170-
end
171-
172172
def create_category(attrs, %Accounts.User{id: user_id}) do
173173
with {:ok, author} <- ensure_author_exists(%Accounts.User{id: user_id}) do
174174
attrs = attrs |> Map.merge(%{author_id: author.id})

lib/mastani_server_web/resolvers/cms_resolver.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ defmodule MastaniServerWeb.Resolvers.CMS do
268268

269269
def update_tag(_root, args, _info), do: CMS.update_tag(args)
270270

271-
def set_tag(_root, ~m(community_id thread id tag_id)a, _info) do
272-
CMS.set_tag(%Community{id: community_id}, thread, %Tag{id: tag_id}, id)
271+
def set_tag(_root, ~m(thread id tag_id)a, _info) do
272+
CMS.set_tag(thread, %Tag{id: tag_id}, id)
273273
end
274274

275275
def set_refined_tag(_root, ~m(community_id thread id topic)a, _info) do

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ defmodule MastaniServerWeb.Schema.CMS.Mutations.Operation do
8282
field :set_tag, :tag do
8383
arg(:id, non_null(:id))
8484
arg(:tag_id, non_null(:id))
85+
# community_id only use for passport check
8586
arg(:community_id, non_null(:id))
8687
arg(:thread, :cms_thread, default_value: :post)
8788

test/mastani_server_web/mutation/cms/job_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ defmodule MastaniServer.Test.Mutation.Job do
198198
assert updated["tags"] |> Enum.any?(&(&1["id"] == to_string(tag.id)))
199199
end
200200

201+
@tag :wip
201202
test "update job tags will replace old city-tags", ~m(owner_conn user job)a do
202203
unique_num = System.unique_integer([:positive, :monotonic])
203204

@@ -208,7 +209,7 @@ defmodule MastaniServer.Test.Mutation.Job do
208209
{:ok, tag2} =
209210
CMS.create_tag(%CMS.Community{id: community2.id}, :job, mock_attrs(:tag), user)
210211

211-
{:ok, _} = CMS.set_tag(community2, :job, tag2, job.id)
212+
{:ok, _} = CMS.set_tag(:job, tag2, job.id)
212213

213214
variables = %{
214215
id: job.id,

test/mastani_server_web/mutation/cms/post_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ defmodule MastaniServer.Test.Mutation.Post do
257257
}
258258
}
259259
"""
260+
@tag :wip
260261
test "auth user can set a valid tag to post", ~m(post)a do
261262
{:ok, community} = db_insert(:community)
262263
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community})
@@ -275,12 +276,12 @@ defmodule MastaniServer.Test.Mutation.Post do
275276
@tag :wip
276277
test "can not set refined tag to post", ~m(post)a do
277278
{:ok, community} = db_insert(:community)
278-
{:ok, _tag} = db_insert(:tag, %{thread: "post", community: community, title: "refined"})
279+
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community, title: "refined"})
279280

280281
passport_rules = %{community.title => %{"post.tag.set" => true}}
281282
rule_conn = simu_conn(:user, cms: passport_rules)
282283

283-
variables = %{id: post.id, communityId: community.id}
284+
variables = %{id: post.id, tagId: tag.id}
284285

285286
assert rule_conn |> mutation_get_error?(@set_tag_query, variables)
286287
end

0 commit comments

Comments
 (0)