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

Commit adee4f2

Browse files
authored
refactor: remove communitt_flag concept (#358)
* refactor: wip * refactor: more tests * fix: tests && warnings
1 parent ff0d2ea commit adee4f2

40 files changed

+255
-525
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ defmodule GroupherServer.CMS do
8080
defdelegate paged_articles(queryable, filter, user), to: ArticleCURD
8181

8282
defdelegate create_article(community, thread, attrs, user), to: ArticleCURD
83-
defdelegate update_article(content, attrs), to: ArticleCURD
83+
defdelegate update_article(article, attrs), to: ArticleCURD
84+
85+
defdelegate mark_delete_article(thread, id), to: ArticleCURD
86+
defdelegate undo_mark_delete_article(thread, id), to: ArticleCURD
8487

8588
defdelegate upvote_article(thread, article_id, user), to: ArticleUpvote
8689
defdelegate undo_upvote_article(thread, article_id, user), to: ArticleUpvote
@@ -99,11 +102,9 @@ defmodule GroupherServer.CMS do
99102

100103
# ArticleCommunity
101104
# >> set flag on article, like: pin / unpin article
102-
defdelegate set_community_flags(community_info, queryable, attrs), to: ArticleCommunity
103105
defdelegate pin_article(thread, id, community_id), to: ArticleCommunity
104106
defdelegate undo_pin_article(thread, id, community_id), to: ArticleCommunity
105-
106-
defdelegate lock_article_comment(content), to: ArticleCommunity
107+
defdelegate lock_article_comment(article), to: ArticleCommunity
107108

108109
# >> tag: set / unset
109110
defdelegate set_tag(thread, tag, content_id), to: ArticleCommunity

lib/groupher_server/cms/delegates/article_community.ex

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
1414
alias Helper.Types, as: T
1515
alias Helper.ORM
1616

17-
alias GroupherServer.CMS.{
18-
Embeds,
19-
Community,
20-
Post,
21-
PostCommunityFlag,
22-
Job,
23-
JobCommunityFlag,
24-
RepoCommunityFlag,
25-
Tag,
26-
PinnedArticle
27-
}
28-
29-
alias GroupherServer.CMS.Repo, as: CMSRepo
17+
alias GroupherServer.CMS.{Embeds, Community, Tag, PinnedArticle}
3018
alias GroupherServer.Repo
3119

3220
alias Ecto.Multi
@@ -68,41 +56,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
6856
########
6957
########
7058
########
71-
########
72-
########
73-
74-
@doc """
75-
trash / untrash articles
76-
"""
77-
def set_community_flags(%Community{id: cid}, content, attrs) do
78-
with {:ok, content} <- ORM.find(content.__struct__, content.id),
79-
{:ok, record} <- insert_flag_record(content, cid, attrs) do
80-
{:ok, struct(content, %{trash: record.trash})}
81-
end
82-
end
83-
84-
def set_community_flags(community_id, content, attrs) do
85-
with {:ok, content} <- ORM.find(content.__struct__, content.id),
86-
{:ok, community} <- ORM.find(Community, community_id),
87-
{:ok, record} <- insert_flag_record(content, community.id, attrs) do
88-
{:ok, struct(content, %{trash: record.trash})}
89-
end
90-
end
91-
92-
defp insert_flag_record(%Post{id: post_id}, community_id, attrs) do
93-
clauses = ~m(post_id community_id)a
94-
PostCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
95-
end
96-
97-
defp insert_flag_record(%Job{id: job_id}, community_id, attrs) do
98-
clauses = ~m(job_id community_id)a
99-
JobCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
100-
end
101-
102-
defp insert_flag_record(%CMSRepo{id: repo_id}, community_id, attrs) do
103-
clauses = ~m(repo_id community_id)a
104-
RepoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
105-
end
10659

10760
@doc """
10861
mirror article to other community

0 commit comments

Comments
 (0)