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.

Commit1d08118

Browse files
authored
refactor: enhance delete article (#410)
* refactor: enhance delete article* refactor: ignore delete document result
1 parent22f2b6f commit1d08118

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ defmodule GroupherServer.CMS do
9292

9393
defdelegatemark_delete_article(thread,id),to:ArticleCURD
9494
defdelegateundo_mark_delete_article(thread,id),to:ArticleCURD
95-
defdelegateremove_article(thread,id),to:ArticleCURD
96-
defdelegateremove_article(thread,id,reason),to:ArticleCURD
95+
defdelegatedelete_article(article),to:ArticleCURD
96+
defdelegatedelete_article(article,reason),to:ArticleCURD
9797

9898
defdelegateupdate_active_timestamp(thread,article),to:ArticleCURD
9999
defdelegatesink_article(thread,id),to:ArticleCURD

‎lib/groupher_server/cms/delegates/article_curd.ex‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
77
importGroupherServer.CMS.Helper.Matcher
88

99
importHelper.Utils,
10-
only:[done:1,pick_by:2,module_to_atom:1,get_config:2,ensure:2,module_to_upcase:1]
10+
only:[
11+
done:1,
12+
pick_by:2,
13+
module_to_atom:1,
14+
get_config:2,
15+
ensure:2,
16+
module_to_upcase:1,
17+
thread_of_article:1
18+
]
1119

1220
importGroupherServer.CMS.Delegate.Helper,only:[mark_viewer_emotion_states:2]
1321
importHelper.ErrorCode
@@ -328,26 +336,28 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
328336
@doc"""
329337
remove article forever
330338
"""
331-
defremove_article(thread,id,reason\\@remove_article_hint)do
332-
with{:ok,info}<-match(thread),
333-
{:ok,article}<-ORM.find(info.model,id,preload:[:communities,[author::user]])do
334-
Multi.new()
335-
|>Multi.run(:remove_article,fn_,_->
336-
article|>ORM.delete()
337-
end)
338-
|>Multi.run(:update_community_article_count,fn_,_->
339-
CommunityCURD.update_community_count_field(article.communities,thread)
340-
end)
341-
|>Multi.run(:update_user_published_meta,fn_,_->
342-
Accounts.update_published_states(article.author.user.id,thread)
343-
end)
344-
|>Multi.run(:delete_document,fn_,_->
345-
Document.remove(thread,id)
346-
end)
347-
# TODO: notify author
348-
|>Repo.transaction()
349-
|>result()
350-
end
339+
defdelete_article(article,reason\\@remove_article_hint)do
340+
article=Repo.preload(article,[:communities,[author::user]])
341+
{:ok,thread}=thread_of_article(article)
342+
343+
Multi.new()
344+
|>Multi.run(:delete_article,fn_,_->
345+
article|>ORM.delete()
346+
end)
347+
|>Multi.run(:update_community_article_count,fn_,_->
348+
CommunityCURD.update_community_count_field(article.communities,thread)
349+
end)
350+
|>Multi.run(:update_user_published_meta,fn_,_->
351+
Accounts.update_published_states(article.author.user.id,thread)
352+
end)
353+
|>Multi.run(:delete_document,fn_,_->
354+
Document.remove(thread,article.id)
355+
# for those history & test setup case
356+
{:ok,:pass}
357+
end)
358+
# TODO: notify author
359+
|>Repo.transaction()
360+
|>result()
351361
end
352362

353363
@specensure_author_exists(User.t())::{:ok,User.t()}
@@ -497,7 +507,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
497507

498508
defpresult({:ok,%{update_edit_status:result}}),do:{:ok,result}
499509
defpresult({:ok,%{update_article:result}}),do:{:ok,result}
500-
defpresult({:ok,%{remove_article:result}}),do:{:ok,result}
510+
defpresult({:ok,%{delete_article:result}}),do:{:ok,result}
501511
# NOTE: for read article, order is import
502512
defpresult({:ok,%{set_viewer_has_states:result}}),do:result|>done()
503513
defpresult({:ok,%{update_article_meta:result}}),do:{:ok,result}

‎lib/groupher_server_web/resolvers/cms_resolver.ex‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ defmodule GroupherServerWeb.Resolvers.CMS do
7373
CMS.update_article(article,args)
7474
end
7575

76-
defdelete_article(_root,%{passport_source:content},_info),do:ORM.delete(content)
76+
defdelete_article(_root,%{passport_source:article},_info)do
77+
CMS.delete_article(article)
78+
end
7779

7880
# #######################
7981
# article actions

‎test/groupher_server/cms/articles/blog_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ defmodule GroupherServer.Test.Articles.Blog do
173173
{:ok,_article_doc}=ORM.find_by(ArticleDocument,%{article_id:blog.id,thread:"BLOG"})
174174
{:ok,_blog_doc}=ORM.find_by(BlogDocument,%{blog_id:blog.id})
175175

176-
CMS.remove_article(:blog,blog.id)
176+
{:ok,_}=CMS.delete_article(blog)
177177

178178
{:error,_}=ORM.find(Blog,blog.id)
179179
{:error,_}=ORM.find_by(ArticleDocument,%{article_id:blog.id,thread:"BLOG"})

‎test/groupher_server/cms/articles/job_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ defmodule GroupherServer.Test.Articles.Job do
174174
{:ok,_article_doc}=ORM.find_by(ArticleDocument,%{article_id:job.id,thread:"JOB"})
175175
{:ok,_job_doc}=ORM.find_by(JobDocument,%{job_id:job.id})
176176

177-
CMS.remove_article(:job,job.id)
177+
{:ok,_}=CMS.delete_article(job)
178178

179179
{:error,_}=ORM.find(Job,job.id)
180180
{:error,_}=ORM.find_by(ArticleDocument,%{article_id:job.id,thread:"JOB"})

‎test/groupher_server/cms/articles/post_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ defmodule GroupherServer.Test.CMS.Articles.Post do
208208
{:ok,_article_doc}=ORM.find_by(ArticleDocument,%{article_id:post.id,thread:"POST"})
209209
{:ok,_post_doc}=ORM.find_by(PostDocument,%{post_id:post.id})
210210

211-
CMS.remove_article(:post,post.id)
211+
{:ok,_}=CMS.delete_article(post)
212212

213213
{:error,_}=ORM.find(Post,post.id)
214214
{:error,_}=ORM.find_by(ArticleDocument,%{article_id:post.id,thread:"POST"})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp