@@ -9,6 +9,7 @@ defmodule GroupherServer.CMS.Community do
99 alias GroupherServer . { Accounts , CMS }
1010
1111 alias CMS . {
12+ Embeds ,
1213 Category ,
1314 CommunityThread ,
1415 CommunitySubscriber ,
@@ -35,13 +36,22 @@ defmodule GroupherServer.CMS.Community do
3536 field ( :raw , :string )
3637 field ( :index , :integer )
3738 field ( :geo_info , :map )
39+ field ( :views , :integer )
3840
41+ embeds_one ( :meta , Embeds.CommunityMeta , on_replace: :delete )
3942 belongs_to ( :author , Accounts.User , foreign_key: :user_id )
4043
4144 has_many ( :threads , { "communities_threads" , CommunityThread } )
4245 has_many ( :subscribers , { "communities_subscribers" , CommunitySubscriber } )
4346 has_many ( :editors , { "communities_editors" , CommunityEditor } )
4447
48+ field ( :articles_count , :integer , default: 0 )
49+ field ( :editors_count , :integer , default: 0 )
50+ field ( :subscribers_count , :integer , default: 0 )
51+
52+ field ( :viewer_has_subscribed , :boolean , default: false , virtual: true )
53+ field ( :viewer_is_editor , :boolean , default: false , virtual: true )
54+
4555 has_one ( :wiki , CommunityWiki )
4656 has_one ( :cheatsheet , CommunityCheatsheet )
4757
@@ -68,6 +78,7 @@ defmodule GroupherServer.CMS.Community do
6878 community
6979 |> cast ( attrs , @ optional_fields ++ @ required_fields )
7080 |> validate_required ( @ required_fields )
81+ |> cast_embed ( :meta , with: & Embeds.CommunityMeta . changeset / 2 )
7182 |> validate_length ( :title , min: 1 , max: 30 )
7283 |> foreign_key_constraint ( :user_id )
7384 |> unique_constraint ( :title , name: :communities_title_index )
@@ -82,6 +93,7 @@ defmodule GroupherServer.CMS.Community do
8293 # |> unique_constraint(:title, name: :communities_title_index)
8394 community
8495 |> cast ( attrs , @ optional_fields ++ @ required_fields )
96+ |> cast_embed ( :meta , with: & Embeds.CommunityMeta . changeset / 2 )
8597 |> validate_length ( :title , min: 1 , max: 30 )
8698 |> foreign_key_constraint ( :user_id )
8799 |> unique_constraint ( :title , name: :communities_title_index )
0 commit comments