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

Commit bf74d0f

Browse files
committed
fix(article-comments): rename pined -> pinned
1 parent 4cf6972 commit bf74d0f

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

lib/groupher_server/cms/article_pined_comment.ex renamed to lib/groupher_server/cms/article_pinned_comment.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule GroupherServer.CMS.ArticlePinedComment do
1+
defmodule GroupherServer.CMS.ArticlePinnedComment do
22
@moduledoc false
33
alias __MODULE__
44

@@ -15,8 +15,8 @@ defmodule GroupherServer.CMS.ArticlePinedComment do
1515
@required_fields ~w(article_comment_id)a
1616
@optional_fields ~w(post_id job_id repo_id)a
1717

18-
@type t :: %ArticlePinedComment{}
19-
schema "articles_pined_comments" do
18+
@type t :: %ArticlePinnedComment{}
19+
schema "articles_pinned_comments" do
2020
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id)
2121
belongs_to(:post, CMS.Post, foreign_key: :post_id)
2222
belongs_to(:job, CMS.Job, foreign_key: :job_id)
@@ -26,14 +26,14 @@ defmodule GroupherServer.CMS.ArticlePinedComment do
2626
end
2727

2828
@doc false
29-
def changeset(%ArticlePinedComment{} = article_pined_comment, attrs) do
29+
def changeset(%ArticlePinnedComment{} = article_pined_comment, attrs) do
3030
article_pined_comment
3131
|> cast(attrs, @required_fields ++ @optional_fields)
3232
|> validate_required(@required_fields)
3333
end
3434

3535
# @doc false
36-
def update_changeset(%ArticlePinedComment{} = article_pined_comment, attrs) do
36+
def update_changeset(%ArticlePinnedComment{} = article_pined_comment, attrs) do
3737
article_pined_comment
3838
|> cast(attrs, @required_fields ++ @optional_fields)
3939
end

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
1515
alias GroupherServer.{Accounts, CMS, Repo}
1616

1717
alias Accounts.User
18-
alias CMS.{ArticleComment, ArticlePinedComment, Embeds}
18+
alias CMS.{ArticleComment, ArticlePinnedComment, Embeds}
1919
alias Ecto.Multi
2020

2121
@max_participator_count ArticleComment.max_participator_count()
@@ -124,7 +124,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
124124
update_article_comments_count(comment, :dec)
125125
end)
126126
|> Multi.run(:remove_pined_comment, fn _, _ ->
127-
ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id})
127+
ORM.findby_delete(ArticlePinnedComment, %{article_comment_id: comment.id})
128128
end)
129129
|> Multi.run(:delete_article_comment, fn _, _ ->
130130
ORM.update(comment, %{body_html: @delete_hint, is_deleted: true})
@@ -235,7 +235,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
235235
}) do
236236
with {:ok, info} <- match(thread),
237237
query <-
238-
from(p in ArticlePinedComment,
238+
from(p in ArticlePinnedComment,
239239
join: c in ArticleComment,
240240
on: p.article_comment_id == c.id,
241241
where: field(p, ^info.foreign_key) == ^article_id,

lib/groupher_server/cms/delegates/article_comment_action.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
1919

2020
alias CMS.{
2121
ArticleComment,
22-
ArticlePinedComment,
22+
ArticlePinnedComment,
2323
ArticleCommentUpvote,
2424
ArticleCommentReply,
2525
Community,
@@ -43,7 +43,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
4343
Multi.new()
4444
|> Multi.run(:checked_pined_comments_count, fn _, _ ->
4545
count_query =
46-
from(p in ArticlePinedComment,
46+
from(p in ArticlePinnedComment,
4747
where: field(p, ^info.foreign_key) == ^full_comment.article.id
4848
)
4949

@@ -58,7 +58,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
5858
ORM.update(comment, %{is_pinned: true})
5959
end)
6060
|> Multi.run(:add_pined_comment, fn _, _ ->
61-
ArticlePinedComment
61+
ArticlePinnedComment
6262
|> ORM.create(
6363
%{article_comment_id: comment.id}
6464
|> Map.put(info.foreign_key, full_comment.article.id)
@@ -76,7 +76,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
7676
ORM.update(comment, %{is_pinned: false})
7777
end)
7878
|> Multi.run(:remove_pined_comment, fn _, _ ->
79-
ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id})
79+
ORM.findby_delete(ArticlePinnedComment, %{article_comment_id: comment.id})
8080
end)
8181
|> Repo.transaction()
8282
|> result()

lib/groupher_server/cms/post.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ defmodule GroupherServer.CMS.Post do
1313
Embeds,
1414
Author,
1515
ArticleComment,
16-
ArticlePinedComment,
1716
Community,
1817
PostComment,
1918
Tag,
@@ -63,7 +62,6 @@ defmodule GroupherServer.CMS.Post do
6362
has_many(:comments, {"posts_comments", PostComment})
6463

6564
has_many(:article_comments, {"articles_comments", ArticleComment})
66-
has_many(:article_pined_comments, {"articles_pined_comments", ArticlePinedComment})
6765
field(:article_comments_count, :integer, default: 0)
6866
field(:article_comments_participators_count, :integer, default: 0)
6967
# 评论参与者,只保留最近 5 个
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule GroupherServer.Repo.Migrations.RenameArticlesPinedComments do
2+
use Ecto.Migration
3+
4+
def change do
5+
rename(table("articles_pined_comments"), to: table("articles_pinned_comments"))
6+
end
7+
end

test/groupher_server/cms/comments/job_comment_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
66
alias Helper.ORM
77
alias GroupherServer.{Accounts, CMS}
88

9-
alias CMS.{ArticleComment, ArticlePinedComment, Embeds, Job}
9+
alias CMS.{ArticleComment, ArticlePinnedComment, Embeds, Job}
1010

1111
@delete_hint CMS.ArticleComment.delete_hint()
1212
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()
@@ -226,7 +226,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
226226

227227
assert comment.is_pinned
228228

229-
{:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{job_id: job.id})
229+
{:ok, pined_record} = ArticlePinnedComment |> ORM.find_by(%{job_id: job.id})
230230
assert pined_record.job_id == job.id
231231
end
232232

@@ -237,7 +237,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
237237
{:ok, comment} = CMS.undo_pin_article_comment(comment.id)
238238

239239
assert not comment.is_pinned
240-
assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id})
240+
assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id})
241241
end
242242

243243
test "pined comments has a limit for each article", ~m(user job)a do
@@ -549,7 +549,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
549549
{:ok, _comment} = ORM.find(ArticleComment, random_comment.id)
550550

551551
{:ok, _} = CMS.delete_article_comment(random_comment)
552-
assert {:error, _comment} = ORM.find(ArticlePinedComment, random_comment.id)
552+
assert {:error, _comment} = ORM.find(ArticlePinnedComment, random_comment.id)
553553
end
554554
end
555555

test/groupher_server/cms/comments/post_comment_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
66
alias Helper.ORM
77
alias GroupherServer.{Accounts, CMS}
88

9-
alias CMS.{ArticleComment, ArticlePinedComment, Embeds, Post}
9+
alias CMS.{ArticleComment, ArticlePinnedComment, Embeds, Post}
1010

1111
@delete_hint CMS.ArticleComment.delete_hint()
1212
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()
@@ -226,7 +226,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
226226

227227
assert comment.is_pinned
228228

229-
{:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{post_id: post.id})
229+
{:ok, pined_record} = ArticlePinnedComment |> ORM.find_by(%{post_id: post.id})
230230
assert pined_record.post_id == post.id
231231
end
232232

@@ -237,7 +237,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
237237
{:ok, comment} = CMS.undo_pin_article_comment(comment.id)
238238

239239
assert not comment.is_pinned
240-
assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id})
240+
assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id})
241241
end
242242

243243
test "pined comments has a limit for each article", ~m(user post)a do
@@ -574,7 +574,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
574574
{:ok, _comment} = ORM.find(ArticleComment, random_comment.id)
575575

576576
{:ok, _} = CMS.delete_article_comment(random_comment)
577-
assert {:error, _comment} = ORM.find(ArticlePinedComment, random_comment.id)
577+
assert {:error, _comment} = ORM.find(ArticlePinnedComment, random_comment.id)
578578
end
579579
end
580580

0 commit comments

Comments
 (0)