Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cover/excoveralls.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions lib/groupher_server/cms/cms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ defmodule GroupherServer.CMS do
defdelegate paged_articles(queryable, filter, user), to: ArticleCURD

defdelegate create_article(community, thread, attrs, user), to: ArticleCURD
defdelegate update_article(content, attrs), to: ArticleCURD
defdelegate update_article(article, attrs), to: ArticleCURD

defdelegate mark_delete_article(thread, id), to: ArticleCURD
defdelegate undo_mark_delete_article(thread, id), to: ArticleCURD

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

# ArticleCommunity
# >> set flag on article, like: pin / unpin article
defdelegate set_community_flags(community_info, queryable, attrs), to: ArticleCommunity
defdelegate pin_article(thread, id, community_id), to: ArticleCommunity
defdelegate undo_pin_article(thread, id, community_id), to: ArticleCommunity

defdelegate lock_article_comment(content), to: ArticleCommunity
defdelegate lock_article_comment(article), to: ArticleCommunity

# >> tag: set / unset
defdelegate set_tag(thread, tag, content_id), to: ArticleCommunity
Expand Down
49 changes: 1 addition & 48 deletions lib/groupher_server/cms/delegates/article_community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
alias Helper.Types, as: T
alias Helper.ORM

alias GroupherServer.CMS.{
Embeds,
Community,
Post,
PostCommunityFlag,
Job,
JobCommunityFlag,
RepoCommunityFlag,
Tag,
PinnedArticle
}

alias GroupherServer.CMS.Repo, as: CMSRepo
alias GroupherServer.CMS.{Embeds, Community, Tag, PinnedArticle}
alias GroupherServer.Repo

alias Ecto.Multi
Expand Down Expand Up @@ -68,41 +56,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
########
########
########
########
########

@doc """
trash / untrash articles
"""
def set_community_flags(%Community{id: cid}, content, attrs) do
with {:ok, content} <- ORM.find(content.__struct__, content.id),
{:ok, record} <- insert_flag_record(content, cid, attrs) do
{:ok, struct(content, %{trash: record.trash})}
end
end

def set_community_flags(community_id, content, attrs) do
with {:ok, content} <- ORM.find(content.__struct__, content.id),
{:ok, community} <- ORM.find(Community, community_id),
{:ok, record} <- insert_flag_record(content, community.id, attrs) do
{:ok, struct(content, %{trash: record.trash})}
end
end

defp insert_flag_record(%Post{id: post_id}, community_id, attrs) do
clauses = ~m(post_id community_id)a
PostCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
end

defp insert_flag_record(%Job{id: job_id}, community_id, attrs) do
clauses = ~m(job_id community_id)a
JobCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
end

defp insert_flag_record(%CMSRepo{id: repo_id}, community_id, attrs) do
clauses = ~m(repo_id community_id)a
RepoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
end

@doc """
mirror article to other community
Expand Down
Loading