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.

Commit920294e

Browse files
committed
refactor(paged-articles): improve should pin judge logic
1 parentb92905f commit920294e

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

‎lib/groupher_server/cms/delegates/article_curd.ex‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
281281
defpadd_pin_articles_ifneed(articles,querable,%{community:community}=filter)do
282282
thread=module_to_thread(querable)
283283

284-
with{:ok,_}<-should_add_pin?(filter),
284+
withtrue<-should_add_pin?(filter),
285285
true<-1==Map.get(articles,:page_number),
286286
{:ok,pinned_articles}<-
287287
PinnedArticle
288288
|>join(:inner,[p],cinassoc(p,:community))
289-
# |> join(:inner, [p], article in assoc(p, ^filter.thread))
290289
|>join(:inner,[p],articleinassoc(p,^thread))
291290
|>where([p,c,article],c.raw==^community)
292291
|>select([p,c,article],article)
@@ -301,13 +300,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
301300
defpadd_pin_articles_ifneed(articles,_querable,_filter),do:articles
302301

303302
# if filter contains like: tags, sort.., then don't add pin article
304-
# TODO: tag
305-
# defp should_add_pin?(%{page: 1, article_tag: :all, sort: :desc_inserted} = _filter) do
306-
defpshould_add_pin?(%{page:1,sort::desc_inserted}=_filter)do
307-
{:ok,:pass}
303+
defpshould_add_pin?(%{page:1,sort::desc_inserted}=filter)do
304+
skip_pinned_fields=[:article_tag,:article_tags]
305+
306+
notEnum.any?(Map.keys(filter),&(&1inskip_pinned_fields))
308307
end
309308

310-
defpshould_add_pin?(_filter),do:{:error,:pass}
309+
defpshould_add_pin?(_filter),do:false
311310

312311
defpconcat_articles(%{total_count:0},non_pinned_articles),do:non_pinned_articles
313312

‎lib/helper/query_builder.ex‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ defmodule Helper.QueryBuilder do
170170
|>where([p],p.inserted_at>=^Timex.beginning_of_year(date))
171171
|>where([p],p.inserted_at<=^Timex.end_of_year(date))
172172

173-
# TODO: remove
174-
{_,:all},queryable->
175-
queryable
176-
177173
{:article_tag,tag_name},queryable->
178174
from(
179175
qinqueryable,

‎test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do
8686
assertexist_in?(article_tag,job["articleTags"],:string_key)
8787
end
8888

89-
@tag:wip2
9089
test"support multi-tag (article_tags) filter",~m(guest_conn user)ado
9190
{:ok,community}=db_insert(:community)
9291
job_attrs=mock_attrs(:job,%{community_id:community.id})
@@ -114,6 +113,39 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do
114113
assertnotexist_in?(article_tag3,job["articleTags"],:string_key)
115114
end
116115

116+
@tag:wip2
117+
test"should not have pined jobs when filter have article_tag or article_tags",
118+
~m(guest_conn user)ado
119+
{:ok,community}=db_insert(:community)
120+
job_attrs=mock_attrs(:job,%{community_id:community.id})
121+
{:ok,pinned_job}=CMS.create_article(community,:job,job_attrs,user)
122+
{:ok,job}=CMS.create_article(community,:job,job_attrs,user)
123+
124+
{:ok,_}=CMS.pin_article(:job,pinned_job.id,community.id)
125+
126+
article_tag_attrs=mock_attrs(:article_tag)
127+
{:ok,article_tag}=CMS.create_article_tag(community,:job,article_tag_attrs,user)
128+
{:ok,_}=CMS.set_article_tag(:job,job.id,article_tag.id)
129+
130+
variables=%{
131+
filter:%{page:1,size:10,community:community.raw,article_tag:article_tag.title}
132+
}
133+
134+
results=guest_conn|>query_result(@query,variables,"pagedJobs")
135+
136+
assertnotexist_in?(pinned_job,results["entries"],:string_key)
137+
assertexist_in?(job,results["entries"],:string_key)
138+
139+
variables=%{
140+
filter:%{page:1,size:10,community:community.raw,article_tags:[article_tag.title]}
141+
}
142+
143+
results=guest_conn|>query_result(@query,variables,"pagedJobs")
144+
145+
assertnotexist_in?(pinned_job,results["entries"],:string_key)
146+
assertexist_in?(job,results["entries"],:string_key)
147+
end
148+
117149
test"support community filter",~m(guest_conn user)ado
118150
{:ok,community}=db_insert(:community)
119151

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp