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

Commit 823b7f3

Browse files
committed
chore(works): plural issue
1 parent d6157ad commit 823b7f3

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

lib/groupher_server_web/schema/Helper/objects.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule GroupherServerWeb.Schema.Helper.Objects do
22
@moduledoc """
33
general fields used in schema definition
44
"""
5-
import Helper.Utils, only: [get_config: 2]
5+
import Helper.Utils, only: [get_config: 2, plural: 1]
66

77
@article_threads get_config(:article, :threads)
88

@@ -19,7 +19,7 @@ defmodule GroupherServerWeb.Schema.Helper.Objects do
1919
@article_threads
2020
|> Enum.map(
2121
&quote do
22-
object unquote(:"paged_#{&1}s") do
22+
object unquote(:"paged_#{plural(&1)}") do
2323
field(:entries, list_of(unquote(&1)))
2424
pagination_fields()
2525
end

lib/groupher_server_web/schema/Helper/queries.ex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
22
@moduledoc """
33
common fields
44
"""
5-
import Helper.Utils, only: [get_config: 2]
5+
import Helper.Utils, only: [get_config: 2, plural: 1]
66

77
alias GroupherServerWeb.Middleware, as: M
88
alias GroupherServerWeb.Resolvers, as: R
@@ -14,8 +14,9 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
1414
@article_threads
1515
|> Enum.map(fn thread ->
1616
quote do
17-
@desc unquote("paged published #{thread}s")
18-
field unquote(:"paged_published_#{thread}s"), unquote(:"paged_#{thread}s") do
17+
@desc unquote("paged published #{plural(thread)}")
18+
field unquote(:"paged_published_#{plural(thread)}"),
19+
unquote(:"paged_#{plural(thread)}") do
1920
arg(:login, non_null(:string))
2021
arg(:filter, non_null(:paged_filter))
2122
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
@@ -32,7 +33,7 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
3233
|> Enum.map(fn thread ->
3334
quote do
3435
@desc unquote("get #{thread} by id")
35-
field unquote(:"search_#{thread}s"), unquote(:"paged_#{thread}s") do
36+
field unquote(:"search_#{plural(thread)}"), unquote(:"paged_#{plural(thread)}") do
3637
arg(:title, non_null(:string))
3738
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
3839

@@ -57,10 +58,10 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
5758
resolve(&R.CMS.read_article/3)
5859
end
5960

60-
@desc unquote("get paged #{thread}s")
61-
field unquote(:"paged_#{thread}s"), unquote(:"paged_#{thread}s") do
61+
@desc unquote("get paged #{plural(thread)}")
62+
field unquote(:"paged_#{plural(thread)}"), unquote(:"paged_#{plural(thread)}") do
6263
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
63-
arg(:filter, non_null(unquote(:"paged_#{thread}s_filter")))
64+
arg(:filter, non_null(unquote(:"paged_#{plural(thread)}_filter")))
6465

6566
middleware(M.PageSizeProof, default_sort: :desc_active)
6667
resolve(&R.CMS.paged_articles/3)
@@ -81,7 +82,4 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
8182
end
8283
end
8384
end
84-
85-
def thread_plural(:works), do: :works
86-
def thread_plural(thread), do: :"#{thread}s"
8785
end

lib/groupher_server_web/schema/cms/cms_metrics.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do
200200

201201
@desc "works_filter doc"
202202
# TODO:
203-
input_object :paged_workss_filter do
203+
input_object :paged_works_filter do
204204
pagination_args()
205205
article_filter_fields()
206206
field(:sort, :sort_enum)

lib/helper/utils/utils.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ defmodule Helper.Utils do
5050
end
5151

5252
@doc """
53-
get plural version of a thread
53+
plural version of the thread
5454
"""
55-
def thread_plural(:works), do: :works
56-
def thread_plural(thread), do: :"#{thread}s"
55+
def plural(:works), do: :works
56+
def plural(thread), do: :"#{thread}s"
5757

5858
@doc """
5959
like || in javascript
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule GroupherServer.Repo.Migrations.AddWorksToCitedArtiments do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:cited_artiments) do
6+
add(:works_id, references(:cms_works, on_delete: :delete_all))
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)