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.

refactor(community): redesign#364

Merged
mydearxym merged 23 commits intodevfromcommunity-redesign
May 22, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
23 commits
Select commitHold shift + click to select a range
e36a8a1
refactor(community): rename table && clean up warnings
mydearxymMay 19, 2021
e507108
refactor(community): re-org macro helper file
mydearxymMay 19, 2021
f1ce81d
refactor(community): wip
mydearxymMay 20, 2021
04bd8a9
refactor(community): wip
mydearxymMay 20, 2021
9ceb26d
refactor(community): more test
mydearxymMay 20, 2021
4508d66
refactor(community): wip
mydearxymMay 20, 2021
74a6d85
refactor(community): wip
mydearxymMay 20, 2021
d628c48
refactor(community): add views to community
mydearxymMay 20, 2021
176c5a2
refactor(community): move articles_count to outside field
mydearxymMay 20, 2021
a1bc01f
refactor(test): skip old post comment test
mydearxymMay 20, 2021
8252888
chore: fmt
mydearxymMay 20, 2021
0ec4880
fix(article): add viewer_has states when read
mydearxymMay 21, 2021
0766085
refactor: sync subscribe count to community
mydearxymMay 21, 2021
8cd6ee8
refactor: move subscribe count & viewer_has logic
mydearxymMay 21, 2021
a49dc93
refactor(community): enhance read community & test
mydearxymMay 22, 2021
af3bfc2
refactor(community): fmt
mydearxymMay 22, 2021
bea44ab
fix(community): meta nil edge-case
mydearxymMay 22, 2021
9f50d45
fix(community): editor count & tests
mydearxymMay 22, 2021
ca57175
fix(community): remove editors subscribers in community fields
mydearxymMay 22, 2021
2ea73d3
fix(community): remove editors subscribers in community fields
mydearxymMay 22, 2021
2f53345
fix(community): error test
mydearxymMay 22, 2021
e78a315
fix(community): error test
mydearxymMay 22, 2021
e56b586
fix(community): error test
mydearxymMay 22, 2021
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 deletioncover/excoveralls.json
View file
Open in desktop

Large diffs are not rendered by default.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ defmodule GroupherServer.Accounts.Delegate.CollectFolder do
user collect folder related
"""
import Ecto.Query, warn: false
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher

alias Helper.Types, as: T
alias Helper.QueryBuilder
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/accounts/delegates/publish.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
# import Helper.ErrorCode
import ShortMaps

import GroupherServer.CMS.Helper.Matcher
import GroupherServer.CMS.Helper.MatcherOld

alias Helper.{ORM, QueryBuilder}
# alias GroupherServer.{Accounts, Repo}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do
@moduledoc """
get contents(posts, jobs ...) that user upvotes
"""
# import GroupherServer.CMS.Helper.Matcher
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1]
import ShortMaps
Expand Down
10 changes: 4 additions & 6 deletionslib/groupher_server/cms/cms.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,10 @@ defmodule GroupherServer.CMS do
# see https://github.com/elixir-lang/elixir/issues/5306

# Community CURD: editors, thread, tag
defdelegate read_community(args), to: CommunityCURD
defdelegate read_community(args, user), to: CommunityCURD
defdelegate create_community(args), to: CommunityCURD
defdelegate update_community(id, args), to: CommunityCURD
# >> editor ..
defdelegate update_editor(user, community, title), to: CommunityCURD
# >> geo info ..
Expand All@@ -51,9 +55,6 @@ defmodule GroupherServer.CMS do
defdelegate unset_article_tag(thread, article_id, tag_id), to: ArticleTag
defdelegate paged_article_tags(filter), to: ArticleTag

defdelegate create_tag(community, thread, attrs, user), to: CommunityCURD
defdelegate update_tag(attrs), to: CommunityCURD

# >> wiki & cheatsheet (sync with github)
defdelegate get_wiki(community), to: CommunitySync
defdelegate get_cheatsheet(community), to: CommunitySync
Expand DownExpand Up@@ -113,9 +114,6 @@ defmodule GroupherServer.CMS do
defdelegate undo_pin_article(thread, id, community_id), to: ArticleCommunity
defdelegate lock_article_comment(article), to: ArticleCommunity

# >> tag: set / unset
defdelegate set_tag(thread, tag, content_id), to: ArticleCommunity
defdelegate unset_tag(thread, tag, content_id), to: ArticleCommunity
# >> community: set / unset
defdelegate mirror_article(thread, article_id, community_id), to: ArticleCommunity
defdelegate unmirror_article(thread, article_id, community_id), to: ArticleCommunity
Expand Down
12 changes: 12 additions & 0 deletionslib/groupher_server/cms/community.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ defmodule GroupherServer.CMS.Community do
alias GroupherServer.{Accounts, CMS}

alias CMS.{
Embeds,
Category,
CommunityThread,
CommunitySubscriber,
Expand All@@ -35,13 +36,22 @@ defmodule GroupherServer.CMS.Community do
field(:raw, :string)
field(:index, :integer)
field(:geo_info, :map)
field(:views, :integer)

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

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

field(:articles_count, :integer, default: 0)
field(:editors_count, :integer, default: 0)
field(:subscribers_count, :integer, default: 0)

field(:viewer_has_subscribed, :boolean, default: false, virtual: true)
field(:viewer_is_editor, :boolean, default: false, virtual: true)

has_one(:wiki, CommunityWiki)
has_one(:cheatsheet, CommunityCheatsheet)

Expand All@@ -68,6 +78,7 @@ defmodule GroupherServer.CMS.Community do
community
|> cast(attrs, @optional_fields ++ @required_fields)
|> validate_required(@required_fields)
|> cast_embed(:meta, with: &Embeds.CommunityMeta.changeset/2)
|> validate_length(:title, min: 1, max: 30)
|> foreign_key_constraint(:user_id)
|> unique_constraint(:title, name: :communities_title_index)
Expand All@@ -82,6 +93,7 @@ defmodule GroupherServer.CMS.Community do
# |> unique_constraint(:title, name: :communities_title_index)
community
|> cast(attrs, @optional_fields ++ @required_fields)
|> cast_embed(:meta, with: &Embeds.CommunityMeta.changeset/2)
|> validate_length(:title, min: 1, max: 30)
|> foreign_key_constraint(:user_id)
|> unique_constraint(:title, name: :communities_title_index)
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/abuse_report.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1, strip_struct: 1, get_config: 2]

import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher
import ShortMaps

alias Helper.ORM
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_collect.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
@moduledoc """
reaction[upvote, collect, watch ...] on article [post, job...]
"""
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1]

Expand Down
16 changes: 8 additions & 8 deletionslib/groupher_server/cms/delegates/article_comment.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
import Helper.ErrorCode

import GroupherServer.CMS.Delegate.Helper, only: [mark_viewer_emotion_states: 3]
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher
import ShortMaps

alias Helper.Types, as: T
Expand DownExpand Up@@ -106,7 +106,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
add_participator_to_article(article, user)
end)
|> Repo.transaction()
|>upsert_comment_result()
|>result()
end
end

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

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

defpupsert_comment_result({:ok, %{create_article_comment: result}}), do: {:ok, result}
defpupsert_comment_result({:ok, %{delete_article_comment: result}}), do: {:ok, result}
defpresult({:ok, %{create_article_comment: result}}), do: {:ok, result}
defpresult({:ok, %{delete_article_comment: result}}), do: {:ok, result}

defpupsert_comment_result({:error, :create_article_comment, result, _steps}) do
defpresult({:error, :create_article_comment, result, _steps}) do
raise_error(:create_comment, result)
end

defpupsert_comment_result({:error, :add_participator, result, _steps}) do
defpresult({:error, :add_participator, result, _steps}) do
{:error, result}
end

defpupsert_comment_result({:error, _, result, _steps}), do: {:error, result}
defpresult({:error, _, result, _steps}), do: {:error, result}
end
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
import GroupherServer.CMS.Delegate.ArticleComment,
only: [add_participator_to_article: 2, do_create_comment: 4, update_article_comments_count: 2]

import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher

alias Helper.Types, as: T
alias Helper.ORM
Expand Down
3 changes: 1 addition & 2 deletionslib/groupher_server/cms/delegates/article_community.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
set / unset operations for Article-like resource
"""
import GroupherServer.CMS.Helper.Matcher
import GroupherServer.CMS.Helper.Matcher2
import Ecto.Query, warn: false

import Helper.ErrorCode
import Helper.Utils, only: [strip_struct: 1, done: 1]
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher

alias Helper.Types, as: T
alias Helper.ORM
Expand Down
63 changes: 50 additions & 13 deletionslib/groupher_server/cms/delegates/article_curd.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
"""
import Ecto.Query, warn: false

import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher

import Helper.Utils,
only: [done: 1, pick_by: 2, integerfy: 1, strip_struct: 1, module_to_thread: 1]
Expand All@@ -19,7 +19,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
alias Accounts.User
alias CMS.{Author, Community, PinnedArticle, Embeds, Delegate}

alias Delegate.{ArticleCommunity, ArticleTag}
alias Delegate.{ArticleCommunity, ArticleTag, CommunityCURD}

alias Ecto.Multi

Expand DownExpand Up@@ -47,8 +47,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
|> Multi.run(:add_viewed_user, fn _, %{inc_views: article} ->
update_viewed_user_list(article, user_id)
end)
|> Multi.run(:set_viewer_has_states, fn _, %{inc_views: article} ->
article_meta = if is_nil(article.meta), do: @default_article_meta, else: article.meta

viewer_has_states = %{
viewer_has_collected: user_id in article_meta.collected_user_ids,
viewer_has_upvoted: user_id in article_meta.upvoted_user_ids,
viewer_has_reported: user_id in article_meta.reported_user_ids
}

{:ok, Map.merge(article, viewer_has_states)}
end)
|> Repo.transaction()
|>read_result()
|>result()
end
end

Expand DownExpand Up@@ -135,6 +146,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
|> Multi.run(:set_article_tags, fn _, %{create_article: article} ->
ArticleTag.set_article_tags(community, thread, article, attrs)
end)
|> Multi.run(:update_community_article_count, fn _, _ ->
CommunityCURD.update_community_count_field(community, thread)
end)
|> Multi.run(:mention_users, fn _, %{create_article: article} ->
Delivery.mention_from_content(community.raw, thread, article, attrs, %User{id: uid})
{:ok, :pass}
Expand DownExpand Up@@ -183,18 +197,42 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
ArticleCommunity.update_edit_status(update_article)
end)
|> Repo.transaction()
|>update_article_result()
|>result()
end

@doc """
mark delete falst for an anticle
"""
def mark_delete_article(thread, id) do
with {:ok, info} <- match(thread) do
ORM.find_update(info.model, %{id: id, mark_delete: true})
with {:ok, info} <- match(thread),
{:ok, article} <- ORM.find(info.model, id, preload: :communities) do
Multi.new()
|> Multi.run(:update_article, fn _, _ ->
ORM.update(article, %{mark_delete: true})
end)
|> Multi.run(:update_community_article_count, fn _, _ ->
CommunityCURD.update_community_count_field(article.communities, thread)
end)
|> Repo.transaction()
|> result()
end
end

@doc """
undo mark delete falst for an anticle
"""
def undo_mark_delete_article(thread, id) do
with {:ok, info} <- match(thread) do
ORM.find_update(info.model, %{id: id, mark_delete: false})
with {:ok, info} <- match(thread),
{:ok, article} <- ORM.find(info.model, id, preload: :communities) do
Multi.new()
|> Multi.run(:update_article, fn _, _ ->
ORM.update(article, %{mark_delete: false})
end)
|> Multi.run(:update_community_article_count, fn _, _ ->
CommunityCURD.update_community_count_field(article.communities, thread)
end)
|> Repo.transaction()
|> result()
end
end

Expand DownExpand Up@@ -406,12 +444,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
end
end

defp update_article_result({:ok, %{update_edit_status: result}}), do: {:ok, result}
defp update_article_result({:error, :update_article, result, _steps}), do: {:error, result}

defp read_result({:ok, %{inc_views: result}}), do: result |> done()
defp result({:ok, %{update_edit_status: result}}), do: {:ok, result}
defp result({:ok, %{update_article: result}}), do: {:ok, result}
defp result({:ok, %{set_viewer_has_states: result}}), do: result |> done()

defpread_result({:error, _, result, _steps}) do
defpresult({:error, _, result, _steps}) do
{:error, result}
end
end
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_emotion.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleEmotion do
CURD and operations for article comments
"""
import Ecto.Query, warn: false
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher

import GroupherServer.CMS.Delegate.Helper, only: [update_emotions_field: 4]

Expand Down
4 changes: 2 additions & 2 deletionslib/groupher_server/cms/delegates/article_tag.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,9 +3,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleTag do
community curd
"""
import Ecto.Query, warn: false
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher
import Helper.Validator.Guards, only: [g_is_id: 1]
import Helper.Utils, only: [done: 1,camelize_map_key: 2,map_atom_values_to_upcase_str: 1]
import Helper.Utils, only: [done: 1, map_atom_values_to_upcase_str: 1]
import GroupherServer.CMS.Delegate.ArticleCURD, only: [ensure_author_exists: 1]
import ShortMaps
import Helper.ErrorCode
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_upvote.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleUpvote do
@moduledoc """
reaction[upvote, collect, watch ...] on article [post, job...]
"""
import GroupherServer.CMS.Helper.Matcher2
import GroupherServer.CMS.Helper.Matcher
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1]

Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/comment_curd.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
import Helper.Utils, only: [done: 1]
import Helper.ErrorCode

import GroupherServer.CMS.Helper.Matcher
import GroupherServer.CMS.Helper.MatcherOld
import ShortMaps

alias Helper.{ORM, QueryBuilder}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp