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

Commit 2f69341

Browse files
authored
refactor(community): redesign (#364)
* refactor(community): rename table && clean up warnings * refactor(community): re-org macro helper file * refactor(community): wip * refactor(community): wip * refactor(community): more test * refactor(community): wip * refactor(community): wip * refactor(community): add views to community * refactor(community): move articles_count to outside field * refactor(test): skip old post comment test * chore: fmt * fix(article): add viewer_has states when read * refactor: sync subscribe count to community * refactor: move subscribe count & viewer_has logic * refactor(community): enhance read community & test * refactor(community): fmt * fix(community): meta nil edge-case * fix(community): editor count & tests * fix(community): remove editors subscribers in community fields * fix(community): remove editors subscribers in community fields * fix(community): error test * fix(community): error test * fix(community): error test
1 parent 9a59768 commit 2f69341

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1655
-634
lines changed

cover/excoveralls.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/groupher_server/accounts/delegates/collect_folder.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule GroupherServer.Accounts.Delegate.CollectFolder do
33
user collect folder related
44
"""
55
import Ecto.Query, warn: false
6-
import GroupherServer.CMS.Helper.Matcher2
6+
import GroupherServer.CMS.Helper.Matcher
77

88
alias Helper.Types, as: T
99
alias Helper.QueryBuilder

lib/groupher_server/accounts/delegates/publish.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
77
# import Helper.ErrorCode
88
import ShortMaps
99

10-
import GroupherServer.CMS.Helper.Matcher
10+
import GroupherServer.CMS.Helper.MatcherOld
1111

1212
alias Helper.{ORM, QueryBuilder}
1313
# alias GroupherServer.{Accounts, Repo}

lib/groupher_server/accounts/delegates/upvoted_articles.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do
22
@moduledoc """
33
get contents(posts, jobs ...) that user upvotes
44
"""
5-
# import GroupherServer.CMS.Helper.Matcher
65
import Ecto.Query, warn: false
76
import Helper.Utils, only: [done: 1]
87
import ShortMaps

lib/groupher_server/cms/cms.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ defmodule GroupherServer.CMS do
3131
# see https://github.com/elixir-lang/elixir/issues/5306
3232

3333
# Community CURD: editors, thread, tag
34+
defdelegate read_community(args), to: CommunityCURD
35+
defdelegate read_community(args, user), to: CommunityCURD
36+
defdelegate create_community(args), to: CommunityCURD
37+
defdelegate update_community(id, args), to: CommunityCURD
3438
# >> editor ..
3539
defdelegate update_editor(user, community, title), to: CommunityCURD
3640
# >> geo info ..
@@ -51,9 +55,6 @@ defmodule GroupherServer.CMS do
5155
defdelegate unset_article_tag(thread, article_id, tag_id), to: ArticleTag
5256
defdelegate paged_article_tags(filter), to: ArticleTag
5357

54-
defdelegate create_tag(community, thread, attrs, user), to: CommunityCURD
55-
defdelegate update_tag(attrs), to: CommunityCURD
56-
5758
# >> wiki & cheatsheet (sync with github)
5859
defdelegate get_wiki(community), to: CommunitySync
5960
defdelegate get_cheatsheet(community), to: CommunitySync
@@ -113,9 +114,6 @@ defmodule GroupherServer.CMS do
113114
defdelegate undo_pin_article(thread, id, community_id), to: ArticleCommunity
114115
defdelegate lock_article_comment(article), to: ArticleCommunity
115116

116-
# >> tag: set / unset
117-
defdelegate set_tag(thread, tag, content_id), to: ArticleCommunity
118-
defdelegate unset_tag(thread, tag, content_id), to: ArticleCommunity
119117
# >> community: set / unset
120118
defdelegate mirror_article(thread, article_id, community_id), to: ArticleCommunity
121119
defdelegate unmirror_article(thread, article_id, community_id), to: ArticleCommunity

lib/groupher_server/cms/community.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule GroupherServer.CMS.Community do
99
alias GroupherServer.{Accounts, CMS}
1010

1111
alias CMS.{
12+
Embeds,
1213
Category,
1314
CommunityThread,
1415
CommunitySubscriber,
@@ -35,13 +36,22 @@ defmodule GroupherServer.CMS.Community do
3536
field(:raw, :string)
3637
field(:index, :integer)
3738
field(:geo_info, :map)
39+
field(:views, :integer)
3840

41+
embeds_one(:meta, Embeds.CommunityMeta, on_replace: :delete)
3942
belongs_to(:author, Accounts.User, foreign_key: :user_id)
4043

4144
has_many(:threads, {"communities_threads", CommunityThread})
4245
has_many(:subscribers, {"communities_subscribers", CommunitySubscriber})
4346
has_many(:editors, {"communities_editors", CommunityEditor})
4447

48+
field(:articles_count, :integer, default: 0)
49+
field(:editors_count, :integer, default: 0)
50+
field(:subscribers_count, :integer, default: 0)
51+
52+
field(:viewer_has_subscribed, :boolean, default: false, virtual: true)
53+
field(:viewer_is_editor, :boolean, default: false, virtual: true)
54+
4555
has_one(:wiki, CommunityWiki)
4656
has_one(:cheatsheet, CommunityCheatsheet)
4757

@@ -68,6 +78,7 @@ defmodule GroupherServer.CMS.Community do
6878
community
6979
|> cast(attrs, @optional_fields ++ @required_fields)
7080
|> validate_required(@required_fields)
81+
|> cast_embed(:meta, with: &Embeds.CommunityMeta.changeset/2)
7182
|> validate_length(:title, min: 1, max: 30)
7283
|> foreign_key_constraint(:user_id)
7384
|> unique_constraint(:title, name: :communities_title_index)
@@ -82,6 +93,7 @@ defmodule GroupherServer.CMS.Community do
8293
# |> unique_constraint(:title, name: :communities_title_index)
8394
community
8495
|> cast(attrs, @optional_fields ++ @required_fields)
96+
|> cast_embed(:meta, with: &Embeds.CommunityMeta.changeset/2)
8597
|> validate_length(:title, min: 1, max: 30)
8698
|> foreign_key_constraint(:user_id)
8799
|> unique_constraint(:title, name: :communities_title_index)

lib/groupher_server/cms/delegates/abuse_report.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
55
import Ecto.Query, warn: false
66
import Helper.Utils, only: [done: 1, strip_struct: 1, get_config: 2]
77

8-
import GroupherServer.CMS.Helper.Matcher2
8+
import GroupherServer.CMS.Helper.Matcher
99
import ShortMaps
1010

1111
alias Helper.ORM

lib/groupher_server/cms/delegates/article_collect.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
22
@moduledoc """
33
reaction[upvote, collect, watch ...] on article [post, job...]
44
"""
5-
import GroupherServer.CMS.Helper.Matcher2
5+
import GroupherServer.CMS.Helper.Matcher
66
import Ecto.Query, warn: false
77
import Helper.Utils, only: [done: 1]
88

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
77
import Helper.ErrorCode
88

99
import GroupherServer.CMS.Delegate.Helper, only: [mark_viewer_emotion_states: 3]
10-
import GroupherServer.CMS.Helper.Matcher2
10+
import GroupherServer.CMS.Helper.Matcher
1111
import ShortMaps
1212

1313
alias Helper.Types, as: T
@@ -106,7 +106,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
106106
add_participator_to_article(article, user)
107107
end)
108108
|> Repo.transaction()
109-
|> upsert_comment_result()
109+
|> result()
110110
end
111111
end
112112

@@ -130,7 +130,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
130130
ORM.update(comment, %{body_html: @delete_hint, is_deleted: true})
131131
end)
132132
|> Repo.transaction()
133-
|> upsert_comment_result()
133+
|> result()
134134
end
135135

136136
# add participator to article-like content (Post, Job ...) and update count
@@ -274,16 +274,16 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
274274
Map.merge(paged_comments, %{entries: entries})
275275
end
276276

277-
defp upsert_comment_result({:ok, %{create_article_comment: result}}), do: {:ok, result}
278-
defp upsert_comment_result({:ok, %{delete_article_comment: result}}), do: {:ok, result}
277+
defp result({:ok, %{create_article_comment: result}}), do: {:ok, result}
278+
defp result({:ok, %{delete_article_comment: result}}), do: {:ok, result}
279279

280-
defp upsert_comment_result({:error, :create_article_comment, result, _steps}) do
280+
defp result({:error, :create_article_comment, result, _steps}) do
281281
raise_error(:create_comment, result)
282282
end
283283

284-
defp upsert_comment_result({:error, :add_participator, result, _steps}) do
284+
defp result({:error, :add_participator, result, _steps}) do
285285
{:error, result}
286286
end
287287

288-
defp upsert_comment_result({:error, _, result, _steps}), do: {:error, result}
288+
defp result({:error, _, result, _steps}), do: {:error, result}
289289
end

lib/groupher_server/cms/delegates/article_comment_action.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
99
import GroupherServer.CMS.Delegate.ArticleComment,
1010
only: [add_participator_to_article: 2, do_create_comment: 4, update_article_comments_count: 2]
1111

12-
import GroupherServer.CMS.Helper.Matcher2
12+
import GroupherServer.CMS.Helper.Matcher
1313

1414
alias Helper.Types, as: T
1515
alias Helper.ORM

0 commit comments

Comments
 (0)