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

Commit bd66c25

Browse files
committed
refactor(cite-workflow): gq endpoint
1 parent f6d4db1 commit bd66c25

File tree

15 files changed

+297
-18
lines changed

15 files changed

+297
-18
lines changed

lib/groupher_server/accounts/delegates/upvoted_articles.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do
1717
get paged upvoted articles
1818
"""
1919
def paged_upvoted_articles(user_id, %{thread: thread} = filter) do
20-
thread_upcase = thread |> to_string |> String.upcase()
21-
where_query = dynamic([a], a.user_id == ^user_id and a.thread == ^thread_upcase)
20+
thread = thread |> to_string |> String.upcase()
21+
where_query = dynamic([a], a.user_id == ^user_id and a.thread == ^thread)
2222

2323
load_upvoted_articles(where_query, filter)
2424
end

lib/groupher_server/cms/delegates/article_collect.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
4646
update_article_reaction_user_list(:collect, article, user_id, :add)
4747
end)
4848
|> Multi.run(:create_collect, fn _, _ ->
49-
thread_upcase = thread |> to_string |> String.upcase()
50-
args = Map.put(%{user_id: user_id, thread: thread_upcase}, info.foreign_key, article.id)
49+
thread = thread |> to_string |> String.upcase()
50+
args = Map.put(%{user_id: user_id, thread: thread}, info.foreign_key, article.id)
5151

5252
ORM.create(ArticleCollect, args)
5353
end)
@@ -131,8 +131,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
131131

132132
defp collection_findby_args(thread, article_id, user_id) do
133133
with {:ok, info} <- match(thread) do
134-
thread_upcase = thread |> to_string |> String.upcase()
135-
%{thread: thread_upcase, user_id: user_id} |> Map.put(info.foreign_key, article_id)
134+
thread = thread |> to_string |> String.upcase()
135+
%{thread: thread, user_id: user_id} |> Map.put(info.foreign_key, article_id)
136136
end
137137
end
138138

lib/groupher_server/cms/delegates/article_community.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
4141
defp pack_pin_args(thread, article_id, community_id) do
4242
with {:ok, info} <- match(thread),
4343
{:ok, community} <- ORM.find(Community, community_id) do
44-
thread_upcase = thread |> to_string |> String.upcase()
44+
thread = thread |> to_string |> String.upcase()
4545

4646
Map.put(
47-
%{community_id: community.id, thread: thread_upcase},
47+
%{community_id: community.id, thread: thread},
4848
info.foreign_key,
4949
article_id
5050
)
@@ -145,12 +145,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
145145

146146
# check if the thread has aready enough pinned articles
147147
defp check_pinned_article_count(community_id, thread) do
148-
thread_upcase = thread |> to_string |> String.upcase()
148+
thread = thread |> to_string |> String.upcase()
149149

150150
query =
151-
from(p in PinnedArticle,
152-
where: p.community_id == ^community_id and p.thread == ^thread_upcase
153-
)
151+
from(p in PinnedArticle, where: p.community_id == ^community_id and p.thread == ^thread)
154152

155153
pinned_articles = query |> Repo.all()
156154

lib/groupher_server/cms/delegates/article_upvote.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleUpvote do
4343
Accounts.achieve(%User{id: achiever_id}, :inc, :upvote)
4444
end)
4545
|> Multi.run(:create_upvote, fn _, _ ->
46-
thread_upcase = thread |> to_string |> String.upcase()
47-
args = Map.put(%{user_id: user_id, thread: thread_upcase}, info.foreign_key, article.id)
46+
thread = thread |> to_string |> String.upcase()
47+
args = Map.put(%{user_id: user_id, thread: thread}, info.foreign_key, article.id)
4848

4949
with {:ok, _} <- ORM.create(ArticleUpvote, args) do
5050
ORM.find(info.model, article.id)

lib/groupher_server/cms/delegates/cited_content.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do
2222

2323
@doc "get paged citing contents"
2424
def paged_citing_contents(cited_by_type, cited_by_id, %{page: page, size: size} = filter) do
25+
cited_by_type = cited_by_type |> to_string |> String.upcase()
26+
2527
CitedContent
2628
|> where([c], c.cited_by_id == ^cited_by_id and c.cited_by_type == ^cited_by_type)
2729
|> QueryBuilder.filter_pack(Map.merge(filter, %{sort: :asc_inserted}))

lib/groupher_server_web/resolvers/cms_resolver.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ defmodule GroupherServerWeb.Resolvers.CMS do
102102
CMS.undo_report_article(thread, id, user)
103103
end
104104

105+
def paged_citing_contents(_root, ~m(content id filter)a, _info) do
106+
CMS.paged_citing_contents(content, id, filter)
107+
end
108+
105109
# #######################
106110
# thread reaction ..
107111
# #######################

lib/groupher_server_web/schema/cms/cms_metrics.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do
4141
value(:share)
4242
end
4343

44+
enum :content do
45+
article_values()
46+
value(:comment)
47+
end
48+
4449
enum :when_enum do
4550
value(:today)
4651
value(:this_week)

lib/groupher_server_web/schema/cms/cms_queries.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
124124
resolve(&R.CMS.paged_reports/3)
125125
end
126126

127+
@desc "paged citings list"
128+
field :paged_citing_contents, :paged_citings do
129+
arg(:id, non_null(:id))
130+
arg(:content, :content, default_value: :post)
131+
arg(:filter, :paged_filter)
132+
133+
resolve(&R.CMS.paged_citing_contents/3)
134+
end
135+
127136
@desc "search communities by title"
128137
field :search_communities, :paged_communities do
129138
arg(:title, non_null(:string))

lib/groupher_server_web/schema/cms/cms_types.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,29 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
317317
timestamp_fields()
318318
end
319319

320+
object :citing do
321+
field(:id, :id)
322+
field(:thread, :string)
323+
field(:title, :string)
324+
field(:block_linker, list_of(:string))
325+
field(:comment_id, :id)
326+
field(:user, :common_user)
327+
328+
timestamp_fields()
329+
end
330+
320331
paged_article_objects()
321332

322333
object :paged_reports do
323334
field(:entries, list_of(:abuse_report))
324335
pagination_fields()
325336
end
326337

338+
object :paged_citings do
339+
field(:entries, list_of(:citing))
340+
pagination_fields()
341+
end
342+
327343
object :paged_categories do
328344
field(:entries, list_of(:category))
329345
pagination_fields()

test/groupher_server/cms/cite_contents/cite_blog_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do
163163
end
164164

165165
describe "[cite pagi]" do
166-
@tag :wip
167166
test "can get paged cited articles.", ~m(user community blog2 blog_attrs)a do
168167
{:ok, comment} =
169168
CMS.create_comment(

0 commit comments

Comments
 (0)