Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit4710244

Browse files
committed
refactor(cms-mutations): extract pin/undo_pin mutation
1 parent520b918 commit4710244

File tree

7 files changed

+60
-78
lines changed

7 files changed

+60
-78
lines changed

‎lib/groupher_server_web/schema/Helper/mutations.ex‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,32 @@ defmodule GroupherServerWeb.Schema.Helper.Mutations do
2626
end
2727
end
2828
end
29+
30+
defmacroarticle_pin_mutation(thread)do
31+
quotedo
32+
@descunquote("pin to#{thread}")
33+
fieldunquote(:"pin_#{thread}"),unquote(thread)do
34+
arg(:id,non_null(:id))
35+
arg(:community_id,non_null(:id))
36+
arg(:thread,unquote(:"#{thread}_thread"),default_value:unquote(thread))
37+
38+
middleware(M.Authorize,:login)
39+
middleware(M.PassportLoader,source::community)
40+
middleware(M.Passport,claim:unquote("cms->c?->#{to_string(thread)}.pin"))
41+
resolve(&R.CMS.pin_article/3)
42+
end
43+
44+
@descunquote("undo pin to#{thread}")
45+
fieldunquote(:"undo_pin_#{thread}"),unquote(thread)do
46+
arg(:id,non_null(:id))
47+
arg(:community_id,non_null(:id))
48+
arg(:thread,unquote(:"#{thread}_thread"),default_value:unquote(thread))
49+
50+
middleware(M.Authorize,:login)
51+
middleware(M.PassportLoader,source::community)
52+
middleware(M.Passport,claim:unquote("cms->c?->#{to_string(thread)}.undo_pin"))
53+
resolve(&R.CMS.undo_pin_article/3)
54+
end
55+
end
56+
end
2957
end

‎lib/groupher_server_web/schema/cms/mutations/job.ex‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,9 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do
7272

7373
#############
7474
article_upvote_mutation(:job)
75+
article_pin_mutation(:job)
7576
#############
7677

77-
@desc"pin a job"
78-
field:pin_job,:jobdo
79-
arg(:id,non_null(:id))
80-
arg(:thread,:job_thread,default_value::job)
81-
arg(:community_id,non_null(:id))
82-
83-
middleware(M.Authorize,:login)
84-
middleware(M.PassportLoader,source::community)
85-
middleware(M.Passport,claim:"cms->c?->job.pin")
86-
resolve(&R.CMS.pin_article/3)
87-
end
88-
89-
@desc"unpin a job"
90-
field:undo_pin_job,:jobdo
91-
arg(:id,non_null(:id))
92-
arg(:thread,:job_thread,default_value::job)
93-
arg(:community_id,non_null(:id))
94-
95-
middleware(M.Authorize,:login)
96-
middleware(M.PassportLoader,source::community)
97-
middleware(M.Passport,claim:"cms->c?->job.undo_pin")
98-
resolve(&R.CMS.undo_pin_article/3)
99-
end
100-
10178
@desc"trash a job, not delete"
10279
field:trash_job,:jobdo
10380
arg(:id,non_null(:id))

‎lib/groupher_server_web/schema/cms/mutations/post.ex‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,9 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do
4646

4747
#############
4848
article_upvote_mutation(:post)
49+
article_pin_mutation(:post)
4950
#############
5051

51-
@desc"pin a post"
52-
field:pin_post,:postdo
53-
arg(:id,non_null(:id))
54-
arg(:community_id,non_null(:id))
55-
arg(:thread,:post_thread,default_value::post)
56-
57-
middleware(M.Authorize,:login)
58-
middleware(M.PassportLoader,source::community)
59-
middleware(M.Passport,claim:"cms->c?->post.pin")
60-
resolve(&R.CMS.pin_article/3)
61-
end
62-
63-
@desc"unpin a post"
64-
field:undo_pin_post,:postdo
65-
arg(:id,non_null(:id))
66-
arg(:thread,:post_thread,default_value::post)
67-
arg(:community_id,non_null(:id))
68-
69-
middleware(M.Authorize,:login)
70-
middleware(M.PassportLoader,source::community)
71-
middleware(M.Passport,claim:"cms->c?->post.undo_pin")
72-
resolve(&R.CMS.undo_pin_article/3)
73-
end
74-
7552
@desc"trash a post, not delete"
7653
field:trash_post,:postdo
7754
arg(:id,non_null(:id))

‎lib/groupher_server_web/schema/cms/mutations/repo.ex‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do
33
CMS mutations for job
44
"""
55
useHelper.GqlSchemaSuite
6+
importGroupherServerWeb.Schema.Helper.Mutations
67

78
object:cms_repo_mutationsdo
89
@desc"create a repo"
@@ -69,29 +70,9 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do
6970
resolve(&R.CMS.update_content/3)
7071
end
7172

72-
@desc"pin a repo"
73-
field:pin_repo,:repodo
74-
arg(:id,non_null(:id))
75-
arg(:thread,:repo_thread,default_value::repo)
76-
arg(:community_id,non_null(:id))
77-
78-
middleware(M.Authorize,:login)
79-
middleware(M.PassportLoader,source::community)
80-
middleware(M.Passport,claim:"cms->c?->repo.pin")
81-
resolve(&R.CMS.pin_article/3)
82-
end
83-
84-
@desc"unpin a repo"
85-
field:undo_pin_repo,:repodo
86-
arg(:id,non_null(:id))
87-
arg(:thread,:repo_thread,default_value::repo)
88-
arg(:community_id,non_null(:id))
89-
90-
middleware(M.Authorize,:login)
91-
middleware(M.PassportLoader,source::community)
92-
middleware(M.Passport,claim:"cms->c?->repo.undo_pin")
93-
resolve(&R.CMS.undo_pin_article/3)
94-
end
73+
#############
74+
article_pin_mutation(:repo)
75+
#############
9576

9677
@desc"trash a repo, not delete"
9778
field:trash_repo,:repodo

‎test/groupher_server_web/mutation/cms/job_flag_test.exs‎renamed to ‎test/groupher_server_web/mutation/cms/flags/job_flag_test.exs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmoduleGroupherServer.Test.Mutation.JobFlagdo
1+
defmoduleGroupherServer.Test.Mutation.Flags.JobFlagdo
22
useGroupherServer.TestTools
33

44
aliasGroupherServer.CMS
@@ -25,6 +25,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
2525
}
2626
}
2727
"""
28+
@tag:wip2
2829
test"auth user can trash job",~m(community job)ado
2930
variables=%{id:job.id,communityId:community.id}
3031

@@ -37,6 +38,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
3738
assertupdated["trash"]==true
3839
end
3940

41+
@tag:wip2
4042
test"unauth user trash job fails",~m(user_conn guest_conn job community)ado
4143
variables=%{id:job.id,communityId:community.id}
4244
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -54,6 +56,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
5456
}
5557
}
5658
"""
59+
@tag:wip2
5760
test"auth user can undo trash job",~m(community job)ado
5861
variables=%{id:job.id,communityId:community.id}
5962

@@ -84,6 +87,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
8487
}
8588
}
8689
"""
90+
@tag:wip2
8791
test"auth user can pin job",~m(community job)ado
8892
variables=%{id:job.id,communityId:community.id}
8993

@@ -95,6 +99,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
9599
assertupdated["id"]==to_string(job.id)
96100
end
97101

102+
@tag:wip2
98103
test"unauth user pin job fails",~m(user_conn guest_conn community job)ado
99104
variables=%{id:job.id,communityId:community.id}
100105
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -112,7 +117,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
112117
}
113118
}
114119
"""
115-
@tag:wip
120+
@tag:wip2
116121
test"auth user can undo pin job",~m(community job)ado
117122
variables=%{id:job.id,communityId:community.id}
118123

@@ -126,6 +131,7 @@ defmodule GroupherServer.Test.Mutation.JobFlag do
126131
assertupdated["isPinned"]==false
127132
end
128133

134+
@tag:wip2
129135
test"unauth user undo pin job fails",~m(user_conn guest_conn community job)ado
130136
variables=%{id:job.id,communityId:community.id}
131137
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})

‎test/groupher_server_web/mutation/cms/post_flag_test.exs‎renamed to ‎test/groupher_server_web/mutation/cms/flags/post_flag_test.exs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmoduleGroupherServer.Test.Mutation.PostFlagdo
1+
defmoduleGroupherServer.Test.Mutation.Flags.PostFlagdo
22
useGroupherServer.TestTools
33

44
aliasGroupherServer.CMS
@@ -25,6 +25,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
2525
}
2626
}
2727
"""
28+
@tag:wip2
2829
test"auth user can trash post",~m(community post)ado
2930
variables=%{id:post.id,communityId:community.id}
3031

@@ -37,6 +38,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
3738
assertupdated["trash"]==true
3839
end
3940

41+
@tag:wip2
4042
test"unauth user trash post fails",~m(user_conn guest_conn post community)ado
4143
variables=%{id:post.id,communityId:community.id}
4244
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -54,6 +56,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
5456
}
5557
}
5658
"""
59+
@tag:wip2
5760
test"auth user can undo trash post",~m(community post)ado
5861
variables=%{id:post.id,communityId:community.id}
5962

@@ -68,6 +71,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
6871
assertupdated["trash"]==false
6972
end
7073

74+
@tag:wip2
7175
test"unauth user undo trash post fails",~m(user_conn guest_conn community post)ado
7276
variables=%{id:post.id,communityId:community.id}
7377
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -84,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
8488
}
8589
}
8690
"""
87-
@tag:wip
91+
@tag:wip2
8892
test"auth user can pin post",~m(community post)ado
8993
variables=%{id:post.id,communityId:community.id}
9094

@@ -96,6 +100,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
96100
assertupdated["id"]==to_string(post.id)
97101
end
98102

103+
@tag:wip2
99104
test"unauth user pin post fails",~m(user_conn guest_conn community post)ado
100105
variables=%{id:post.id,communityId:community.id}
101106
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -113,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
113118
}
114119
}
115120
"""
116-
@tag:wip
121+
@tag:wip2
117122
test"auth user can undo pin post",~m(community post)ado
118123
variables=%{id:post.id,communityId:community.id}
119124

@@ -126,6 +131,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do
126131
assertupdated["id"]==to_string(post.id)
127132
end
128133

134+
@tag:wip2
129135
test"unauth user undo pin post fails",~m(user_conn guest_conn community post)ado
130136
variables=%{id:post.id,communityId:community.id}
131137
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})

‎test/groupher_server_web/mutation/cms/repo_flag_test.exs‎renamed to ‎test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmoduleGroupherServer.Test.Mutation.RepoFlagdo
1+
defmoduleGroupherServer.Test.Mutation.Flags.RepoFlagdo
22
useGroupherServer.TestTools
33

44
aliasGroupherServer.CMS
@@ -25,6 +25,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
2525
}
2626
}
2727
"""
28+
@tag:wip2
2829
test"auth user can trash repo",~m(community repo)ado
2930
variables=%{id:repo.id,communityId:community.id}
3031

@@ -37,6 +38,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
3738
assertupdated["trash"]==true
3839
end
3940

41+
@tag:wip2
4042
test"unauth user trash repo fails",~m(user_conn guest_conn repo community)ado
4143
variables=%{id:repo.id,communityId:community.id}
4244
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -54,6 +56,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
5456
}
5557
}
5658
"""
59+
@tag:wip2
5760
test"auth user can undo trash repo",~m(community repo)ado
5861
variables=%{id:repo.id,communityId:community.id}
5962

@@ -68,6 +71,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
6871
assertupdated["trash"]==false
6972
end
7073

74+
@tag:wip2
7175
test"unauth user undo trash repo fails",~m(user_conn guest_conn community repo)ado
7276
variables=%{id:repo.id,communityId:community.id}
7377
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -84,6 +88,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
8488
}
8589
}
8690
"""
91+
@tag:wip2
8792
test"auth user can pin repo",~m(community repo)ado
8893
variables=%{id:repo.id,communityId:community.id}
8994

@@ -95,6 +100,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
95100
assertupdated["id"]==to_string(repo.id)
96101
end
97102

103+
@tag:wip2
98104
test"unauth user pin repo fails",~m(user_conn guest_conn community repo)ado
99105
variables=%{id:repo.id,communityId:community.id}
100106
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
@@ -112,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
112118
}
113119
}
114120
"""
115-
@tag:wip
121+
@tag:wip2
116122
test"auth user can undo pin repo",~m(community repo)ado
117123
variables=%{id:repo.id,communityId:community.id}
118124

@@ -125,6 +131,7 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do
125131
assertupdated["id"]==to_string(repo.id)
126132
end
127133

134+
@tag:wip2
128135
test"unauth user undo pin repo fails",~m(user_conn guest_conn community repo)ado
129136
variables=%{id:repo.id,communityId:community.id}
130137
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp