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.

Commit3e872e4

Browse files
committed
refactor(cite-workflow): wip
1 parent617cd3d commit3e872e4

File tree

5 files changed

+94
-10
lines changed

5 files changed

+94
-10
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule GroupherServer.CMS do
1212
ArticleCURD,
1313
ArticleCommunity,
1414
ArticleEmotion,
15+
CitedContent,
1516
CommentCurd,
1617
ArticleCollect,
1718
ArticleUpvote,
@@ -96,6 +97,8 @@ defmodule GroupherServer.CMS do
9697
defdelegatesink_article(thread,id),to:ArticleCURD
9798
defdelegateundo_sink_article(thread,id),to:ArticleCURD
9899

100+
defdelegatepaged_citing_contents(id,filter),to:CitedContent
101+
99102
defdelegateupvote_article(thread,article_id,user),to:ArticleUpvote
100103
defdelegateundo_upvote_article(thread,article_id,user),to:ArticleUpvote
101104

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
defmoduleGroupherServer.CMS.Delegate.CitedContentdo
2+
@moduledoc"""
3+
CURD operation on post/job ...
4+
"""
5+
importEcto.Query,warn:false
6+
7+
importGroupherServer.CMS.Helper.Matcher
8+
importHelper.Utils,only:[done:1,get_config:2]
9+
importShortMaps
10+
11+
aliasGroupherServer.{CMS,Repo}
12+
aliasHelper.ORM
13+
14+
aliasCMS.Model.CitedContent
15+
16+
@article_threadsget_config(:article,:threads)
17+
@cited_preloads@article_threads|>Enum.map(&Keyword.new([{&1,[author::user]}]))
18+
19+
"""
20+
article:
21+
thread title timestamp who
22+
23+
comment:
24+
thread title/的评论(digest)中 timestamp who
25+
26+
%Article {
27+
thread: "",
28+
id: "",
29+
title: "",
30+
updatedAt: "",
31+
user: %User{},
32+
block_linker: [],
33+
34+
in_comment: boolean
35+
36+
user: %User{},
37+
}
38+
"""
39+
40+
@doc"get paged citing contents"
41+
defpaged_citing_contents(cited_by_id,%{page:page,size:size}=filter)do
42+
CitedContent
43+
|>where([c],c.cited_by_id==^cited_by_id)
44+
|>ORM.paginater(~m(page size)a)
45+
|>extract_contents
46+
|>IO.inspect(label:"bb")
47+
end
48+
49+
defextract_contents(%{entries:entries}=paged_contents)do
50+
entries=entries|>Repo.preload(@cited_preloads)|>Enum.map(&shape_article(&1))
51+
52+
Map.put(paged_contents,:entries,entries)
53+
end
54+
55+
defshape_article(%CitedContent{}=cited)do
56+
thread=cited.cited_by_type|>String.downcase()|>String.to_atom()
57+
# original_community
58+
block_linker=cited.block_linker
59+
article=Map.get(cited,thread)
60+
61+
thread=get_in(article,[:meta])|>Map.get(:thread)
62+
user=get_in(article,[:author,:user])|>Map.take([:login,:nickname,:avatar])
63+
64+
article
65+
|>Map.take([:title,:updated_at])
66+
|>Map.merge(%{user:user,thread:thread,block_linker:block_linker})
67+
end
68+
end

‎test/groupher_server/cms/cite_contents/cite_blog_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do
7373
assertblog.meta.citing_count==0
7474
end
7575

76-
@tag:wip
7776
test"cited comment itself should not work",~m(user blog)ado
7877
{:ok,cited_comment}=CMS.create_comment(:blog,blog.id,mock_rich_text("hello"),user)
7978

@@ -91,7 +90,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do
9190
assertcited_comment.meta.citing_count==0
9291
end
9392

94-
@tag:wip
9593
test"can cite blog's comment in blog",~m(community user blog blog2 blog_attrs)ado
9694
{:ok,comment}=CMS.create_comment(:blog,blog.id,mock_rich_text("hello"),user)
9795

@@ -111,7 +109,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do
111109
assertcite_content.cited_by_type=="COMMENT"
112110
end
113111

114-
@tag:wip
115112
test"can cite a comment in a comment",~m(user blog)ado
116113
{:ok,cited_comment}=CMS.create_comment(:blog,blog.id,mock_rich_text("hello"),user)
117114

‎test/groupher_server/cms/cite_contents/cite_job_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do
7373
assertjob.meta.citing_count==0
7474
end
7575

76-
@tag:wip
7776
test"cited comment itself should not work",~m(user job)ado
7877
{:ok,cited_comment}=CMS.create_comment(:job,job.id,mock_rich_text("hello"),user)
7978

@@ -91,7 +90,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do
9190
assertcited_comment.meta.citing_count==0
9291
end
9392

94-
@tag:wip
9593
test"can cite job's comment in job",~m(community user job job2 job_attrs)ado
9694
{:ok,comment}=CMS.create_comment(:job,job.id,mock_rich_text("hello"),user)
9795

@@ -111,7 +109,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do
111109
assertcite_content.cited_by_type=="COMMENT"
112110
end
113111

114-
@tag:wip
115112
test"can cite a comment in a comment",~m(user job)ado
116113
{:ok,cited_comment}=CMS.create_comment(:job,job.id,mock_rich_text("hello"),user)
117114

‎test/groupher_server/cms/cite_contents/cite_post_test.exs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
2727
{:ok,~m(user user2 community post post2 post3 post4 post5 post_attrs)a}
2828
end
2929

30+
describe"[cite pagi]"do
31+
@tag:wip
32+
test"--can get paged cited articles.",~m(user community post2 post_attrs)ado
33+
body=
34+
mock_rich_text(
35+
~s(the <a href=#{@site_host}/post/#{post2.id} />),
36+
~s(the <a href=#{@site_host}/post/#{post2.id} />)
37+
)
38+
39+
post_attrs=post_attrs|>Map.merge(%{body:body})
40+
{:ok,post_x}=CMS.create_article(community,:post,post_attrs,user)
41+
42+
body=mock_rich_text(~s(the <a href=#{@site_host}/post/#{post2.id} />))
43+
post_attrs=post_attrs|>Map.merge(%{body:body})
44+
{:ok,post_y}=CMS.create_article(community,:post,post_attrs,user)
45+
46+
CiteTasks.handle(post_x)
47+
CiteTasks.handle(post_y)
48+
49+
CMS.paged_citing_contents(post2.id,%{page:1,size:10})
50+
end
51+
end
52+
3053
describe"[cite basic]"do
3154
#
3255
test"cited multi post should work",~m(user community post2 post3 post4 post5 post_attrs)ado
@@ -62,7 +85,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
6285
assertpost5.meta.citing_count==1
6386
end
6487

65-
@tag:wip
6688
test"cited post itself should not work",~m(user community post_attrs)ado
6789
{:ok,post}=CMS.create_article(community,:post,post_attrs,user)
6890

@@ -75,7 +97,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
7597
assertpost.meta.citing_count==0
7698
end
7799

78-
@tag:wip
79100
test"cited comment itself should not work",~m(user post)ado
80101
{:ok,cited_comment}=CMS.create_comment(:post,post.id,mock_rich_text("hello"),user)
81102

@@ -93,7 +114,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
93114
assertcited_comment.meta.citing_count==0
94115
end
95116

96-
@tag:wip
97117
test"can cite post's comment in post",~m(community user post post2 post_attrs)ado
98118
{:ok,comment}=CMS.create_comment(:post,post.id,mock_rich_text("hello"),user)
99119

@@ -113,7 +133,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
113133
assertcite_content.cited_by_type=="COMMENT"
114134
end
115135

116-
@tag:wip
117136
test"can cite a comment in a comment",~m(user post)ado
118137
{:ok,cited_comment}=CMS.create_comment(:post,post.id,mock_rich_text("hello"),user)
119138

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp