Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 6 additions & 53 deletions lib/groupher_server/cms/delegates/article_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -254,52 +254,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
ORM.find_by(Author, user_id: changeset.data.user_id)
end

defp domain_filter_query(CMS.Job = queryable, filter) do
Enum.reduce(filter, queryable, fn
{:salary, salary}, queryable ->
queryable |> where([content], content.salary == ^salary)

{:field, field}, queryable ->
queryable |> where([content], content.field == ^field)

{:finance, finance}, queryable ->
queryable |> where([content], content.finance == ^finance)

{:scale, scale}, queryable ->
queryable |> where([content], content.scale == ^scale)

{:exp, exp}, queryable ->
if exp == "不限", do: queryable, else: queryable |> where([content], content.exp == ^exp)

{:education, education}, queryable ->
cond do
education == "大专" ->
queryable
|> where([content], content.education == "大专" or content.education == "不限")

education == "本科" ->
queryable
|> where([content], content.education != "不限")
|> where([content], content.education != "大专")

education == "硕士" ->
queryable
|> where([content], content.education != "不限")
|> where([content], content.education != "大专")
|> where([content], content.education != "本科")

education == "不限" ->
queryable

true ->
queryable |> where([content], content.education == ^education)
end

{_, _}, queryable ->
queryable
end)
end

defp domain_filter_query(CMS.Repo = queryable, filter) do
Enum.reduce(filter, queryable, fn
{:sort, :most_github_star}, queryable ->
Expand Down Expand Up @@ -327,12 +281,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
defp add_pin_articles_ifneed(articles, querable, %{community: community} = filter) do
thread = module_to_thread(querable)

with {:ok, _} <- should_add_pin?(filter),
with true <- should_add_pin?(filter),
true <- 1 == Map.get(articles, :page_number),
{:ok, pinned_articles} <-
PinnedArticle
|> join(:inner, [p], c in assoc(p, :community))
# |> join(:inner, [p], article in assoc(p, ^filter.thread))
|> join(:inner, [p], article in assoc(p, ^thread))
|> where([p, c, article], c.raw == ^community)
|> select([p, c, article], article)
Expand All @@ -347,13 +300,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
defp add_pin_articles_ifneed(articles, _querable, _filter), do: articles

# if filter contains like: tags, sort.., then don't add pin article
# TODO: tag
# defp should_add_pin?(%{page: 1, article_tag: :all, sort: :desc_inserted} = _filter) do
defp should_add_pin?(%{page: 1, sort: :desc_inserted} = _filter) do
{:ok, :pass}
defp should_add_pin?(%{page: 1, sort: :desc_inserted} = filter) do
skip_pinned_fields = [:article_tag, :article_tags]

not Enum.any?(Map.keys(filter), &(&1 in skip_pinned_fields))
end

defp should_add_pin?(_filter), do: {:error, :pass}
defp should_add_pin?(_filter), do: false

defp concat_articles(%{total_count: 0}, non_pinned_articles), do: non_pinned_articles

Expand Down
14 changes: 2 additions & 12 deletions lib/groupher_server/cms/job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,20 @@ defmodule GroupherServer.CMS.Job do
alias Helper.HTML

@timestamps_opts [type: :utc_datetime_usec]
@required_fields ~w(title company company_logo body digest length)a
@required_fields ~w(title company body digest length)a
@article_cast_fields general_article_fields(:cast)
@optional_fields @article_cast_fields ++
~w(desc company_link link_addr copy_right salary exp education field finance scale)a
@optional_fields @article_cast_fields ++ ~w(desc company_link link_addr copy_right)a

@type t :: %Job{}
schema "cms_jobs" do
field(:title, :string)
field(:company, :string)
field(:company_logo, :string)
field(:company_link, :string)
field(:desc, :string)
field(:body, :string)

field(:link_addr, :string)
field(:copy_right, :string)

field(:salary, :string)
field(:exp, :string)
field(:education, :string)
field(:field, :string)
field(:finance, :string)
field(:scale, :string)

field(:digest, :string)
field(:length, :integer)

Expand Down
1 change: 1 addition & 0 deletions lib/groupher_server_web/schema/Helper/fields.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
field(:when, :when_enum)
field(:length, :length_enum)
field(:article_tag, :string)
field(:article_tags, list_of(:string))
field(:community, :string)
end
end
Expand Down
113 changes: 0 additions & 113 deletions lib/groupher_server_web/schema/account/account_misc.ex

This file was deleted.

7 changes: 0 additions & 7 deletions lib/groupher_server_web/schema/cms/cms_metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,6 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do
pagination_args()
article_filter_fields()
field(:sort, :sort_enum)

field(:salary, :string)
field(:exp, :string)
field(:education, :string)
field(:field, :string)
field(:finance, :string)
field(:scale, :string)
end

@desc "article_filter doc"
Expand Down
Loading