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

Commit ec1a26e

Browse files
committed
refactor(macros): wip
1 parent af04839 commit ec1a26e

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

lib/groupher_server/cms/helper/macros.ex

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ defmodule GroupherServer.CMS.Helper.Macros do
55
import Helper.Utils, only: [get_config: 2]
66

77
alias GroupherServer.{CMS, Accounts}
8-
98
alias Accounts.Model.User
109

1110
alias CMS.Model.{
@@ -32,7 +31,7 @@ defmodule GroupherServer.CMS.Helper.Macros do
3231
3332
add(:post_id, references(:cms_posts, on_delete: :delete_all))
3433
add(:job_id, references(:cms_jobs, on_delete: :delete_all))
35-
add(:repo_id, references(:cms_jobs, on_delete: :delete_all))
34+
add(:repo_id, references(:cms_repos, on_delete: :delete_all))
3635
...
3736
"""
3837
defmacro article_belongs_to_fields() do
@@ -41,7 +40,7 @@ defmodule GroupherServer.CMS.Helper.Macros do
4140
quote do
4241
belongs_to(
4342
unquote(thread),
44-
Module.concat(CMS.Model, unquote(thread) |> to_string |> Recase.to_pascal()),
43+
Module.concat(CMS.Model, Recase.to_pascal(to_string(unquote(thread)))),
4544
foreign_key: unquote(:"#{thread}_id")
4645
)
4746
end
@@ -184,6 +183,7 @@ defmodule GroupherServer.CMS.Helper.Macros do
184183
"""
185184
defmacro general_article_fields do
186185
quote do
186+
field(:title, :string)
187187
belongs_to(:author, Author)
188188

189189
field(:views, :integer, default: 0)
@@ -216,19 +216,20 @@ defmodule GroupherServer.CMS.Helper.Macros do
216216
217217
create(unique_index(:communities_[article]s, [:community_id, :[article]_id]))
218218
"""
219-
defmacro community_article_fields() do
220-
@article_threads
221-
|> Enum.map(fn thread ->
222-
quote do
223-
many_to_many(
224-
unquote(:"#{thread}s"),
225-
Module.concat(CMS.Model, unquote(thread) |> to_string |> Recase.to_pascal()),
226-
join_through: unquote("communities_#{to_string(thread)}s"),
227-
join_keys: [community_id: :id] ++ Keyword.new([{unquote(:"#{thread}_id"), :id}])
228-
)
229-
end
230-
end)
231-
end
219+
220+
# defmacro community_article_fields() do
221+
# @article_threads
222+
# |> Enum.map(fn thread ->
223+
# quote do
224+
# many_to_many(
225+
# unquote(:"#{thread}s"),
226+
# Module.concat(CMS.Model, Recase.to_pascal(to_string(unquote(thread)))),
227+
# join_through: unquote("communities_#{to_string(thread)}s"),
228+
# join_keys: [community_id: :id] ++ Keyword.new([{unquote(:"#{thread}_id"), :id}])
229+
# )
230+
# end
231+
# end)
232+
# end
232233

233234
@doc """
234235
for GroupherServer.CMS.[Article]
@@ -237,7 +238,7 @@ defmodule GroupherServer.CMS.Helper.Macros do
237238
add(:community_id, references(:communities, on_delete: :delete_all), null: false)
238239
add(:[article]_id, references(:cms_[article]s, on_delete: :delete_all), null: false)
239240
240-
create(unique_index(:communities_job_[article]s, [:community_id, :[article]_id]))
241+
create(unique_index(:communities_join_[article]s, [:community_id, :[article]_id]))
241242
"""
242243
defmacro article_communities_field(thread) do
243244
quote do

lib/groupher_server/cms/models/community.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule GroupherServer.CMS.Model.Community do
7070
# on_replace: :delete
7171
)
7272

73-
community_article_fields()
73+
# community_article_fields()
7474
#
7575
# posts_block_list ...
7676
timestamps(type: :utc_datetime)

lib/groupher_server/cms/models/job.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ defmodule GroupherServer.CMS.Model.Job do
1919

2020
@type t :: %Job{}
2121
schema "cms_jobs" do
22-
field(:title, :string)
2322
field(:company, :string)
2423
field(:company_link, :string)
2524
field(:desc, :string)

lib/groupher_server/cms/models/post.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule GroupherServer.CMS.Model.Post do
2323
@type t :: %Post{}
2424
schema "cms_posts" do
2525
field(:body, :string)
26-
field(:title, :string)
2726
field(:digest, :string)
2827
field(:link_addr, :string)
2928
field(:copy_right, :string)

lib/groupher_server/cms/models/repo.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ defmodule GroupherServer.CMS.Model.Repo do
2020

2121
@type t :: %Repo{}
2222
schema "cms_repos" do
23-
field(:title, :string)
2423
field(:owner_name, :string)
2524
field(:owner_url, :string)
2625
field(:repo_url, :string)

0 commit comments

Comments
 (0)