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

Commit d54319f

Browse files
authored
refactor(macros): clean up (#389)
* refactor(macros): wip * refactor(macros): clean up unused macros
1 parent af04839 commit d54319f

File tree

5 files changed

+4
-32
lines changed

5 files changed

+4
-32
lines changed

lib/groupher_server/cms/helper/macros.ex

+4-27
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)
@@ -207,37 +207,14 @@ defmodule GroupherServer.CMS.Helper.Macros do
207207
end
208208
end
209209

210-
@doc """
211-
for GroupherServer.CMS.Model.Community
212-
213-
# TABLE: "communities_[article]s"
214-
add(:community_id, references(:communities, on_delete: :delete_all), null: false)
215-
add(:[article]_id, references(:cms_[article]s, on_delete: :delete_all), null: false)
216-
217-
create(unique_index(:communities_[article]s, [:community_id, :[article]_id]))
218-
"""
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
232-
233210
@doc """
234211
for GroupherServer.CMS.[Article]
235212
236213
# TABLE: "communities_join_[article]s"
237214
add(:community_id, references(:communities, on_delete: :delete_all), null: false)
238215
add(:[article]_id, references(:cms_[article]s, on_delete: :delete_all), null: false)
239216
240-
create(unique_index(:communities_job_[article]s, [:community_id, :[article]_id]))
217+
create(unique_index(:communities_join_[article]s, [:community_id, :[article]_id]))
241218
"""
242219
defmacro article_communities_field(thread) do
243220
quote do

lib/groupher_server/cms/models/community.ex

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ defmodule GroupherServer.CMS.Model.Community do
7070
# on_replace: :delete
7171
)
7272

73-
community_article_fields()
74-
#
7573
# posts_block_list ...
7674
timestamps(type: :utc_datetime)
7775
end

lib/groupher_server/cms/models/job.ex

-1
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

-1
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

-1
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)