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

Commit 6736313

Browse files
committed
refactor(pinned-article): add/alter is_pinned field
1 parent 01dc257 commit 6736313

File tree

7 files changed

+33
-14
lines changed

7 files changed

+33
-14
lines changed

lib/groupher_server/cms/article_comment.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule GroupherServer.CMS.ArticleComment do
2020

2121
@required_fields ~w(body_html author_id)a
2222
@optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a
23-
@updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pined)a
23+
@updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a
2424

2525
@max_participator_count 5
2626
@max_parent_replies_count 3
@@ -66,7 +66,7 @@ defmodule GroupherServer.CMS.ArticleComment do
6666
field(:upvotes_count, :integer, default: 0)
6767

6868
# 是否置顶
69-
field(:is_pined, :boolean, default: false)
69+
field(:is_pinned, :boolean, default: false)
7070

7171
belongs_to(:author, Accounts.User, foreign_key: :author_id)
7272
belongs_to(:post, Post, foreign_key: :post_id)

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
4646
def list_article_comments(thread, article_id, filters, mode, user \\ nil)
4747

4848
def list_article_comments(thread, article_id, filters, :timeline, user) do
49-
where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pined)
49+
where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pinned)
5050
do_list_article_comment(thread, article_id, filters, where_query, user)
5151
end
5252

@@ -57,19 +57,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
5757
where_query =
5858
dynamic(
5959
[c],
60-
is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pined
60+
is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pinned
6161
)
6262

6363
do_list_article_comment(thread, article_id, filters, where_query, user)
6464
end
6565

6666
def list_folded_article_comments(thread, article_id, filters) do
67-
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pined)
67+
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned)
6868
do_list_article_comment(thread, article_id, filters, where_query, nil)
6969
end
7070

7171
def list_folded_article_comments(thread, article_id, filters, user) do
72-
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pined)
72+
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned)
7373
do_list_article_comment(thread, article_id, filters, where_query, user)
7474
end
7575

@@ -129,7 +129,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
129129
end
130130
end)
131131
|> Multi.run(:update_comment_flag, fn _, _ ->
132-
ORM.update(comment, %{is_pined: true})
132+
ORM.update(comment, %{is_pinned: true})
133133
end)
134134
|> Multi.run(:add_pined_comment, fn _, _ ->
135135
ArticlePinedComment
@@ -147,7 +147,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
147147
with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do
148148
Multi.new()
149149
|> Multi.run(:update_comment_flag, fn _, _ ->
150-
ORM.update(comment, %{is_pined: false})
150+
ORM.update(comment, %{is_pinned: false})
151151
end)
152152
|> Multi.run(:remove_pined_comment, fn _, _ ->
153153
ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id})

lib/groupher_server/cms/delegates/article_operation.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
4141
{:ok, _} <- check_pinned_article_count(community_id, thread) do
4242
Multi.new()
4343
|> Multi.run(:update_article_pinned_flag, fn _, _ ->
44-
# ORM.update(comment, %{is_pined: true})
44+
# ORM.update(comment, %{is_pinned: true})
4545
{:ok, :pass}
4646
end)
4747
|> Multi.run(:create_pinned_article, fn _, _ ->

lib/groupher_server_web/schema/cms/cms_types.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
362362
field(:id, :id)
363363
field(:body_html, :string)
364364
field(:author, :user, resolve: dataloader(CMS, :author))
365-
field(:is_pined, :boolean)
365+
field(:is_pinned, :boolean)
366366
field(:floor, :integer)
367367
field(:upvotes_count, :integer)
368368
field(:emotions, :article_comment_emotions)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule GroupherServer.Repo.Migrations.AdjustPinFieldOnArticles do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:cms_posts) do
6+
add(:is_pinned, :boolean, default: false)
7+
end
8+
9+
alter table(:cms_jobs) do
10+
add(:is_pinned, :boolean, default: false)
11+
end
12+
13+
alter table(:cms_repos) do
14+
add(:is_pinned, :boolean, default: false)
15+
end
16+
17+
rename(table(:articles_comments), :is_pined, to: :is_pinned)
18+
end
19+
end

test/groupher_server/cms/article_comment_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
223223
{:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user)
224224
{:ok, comment} = ORM.find(ArticleComment, comment.id)
225225

226-
assert not comment.is_pined
226+
assert not comment.is_pinned
227227

228228
{:ok, comment} = CMS.pin_article_comment(comment.id)
229229
{:ok, comment} = ORM.find(ArticleComment, comment.id)
230230

231-
assert comment.is_pined
231+
assert comment.is_pinned
232232

233233
{:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{post_id: post.id})
234234
assert pined_record.post_id == post.id
@@ -240,7 +240,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
240240
{:ok, _comment} = CMS.pin_article_comment(comment.id)
241241
{:ok, comment} = CMS.undo_pin_article_comment(comment.id)
242242

243-
assert not comment.is_pined
243+
assert not comment.is_pinned
244244
assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id})
245245
end
246246

test/groupher_server_web/query/cms/article_comment_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Query.ArticleComment do
6868
id
6969
nickname
7070
}
71-
isPined
71+
isPinned
7272
floor
7373
upvotesCount
7474

0 commit comments

Comments
 (0)