diff --git a/lib/groupher_server/cms/delegates/community_crud.ex b/lib/groupher_server/cms/delegates/community_crud.ex index 1300bb9..d396293 100644 --- a/lib/groupher_server/cms/delegates/community_crud.ex +++ b/lib/groupher_server/cms/delegates/community_crud.ex @@ -134,7 +134,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityCRUD do """ def update_dashboard(community_slug, :base_info, args) do main_fields = - Map.take(args, [:title, :desc, :logo, :favicon, :slug]) + Map.take(args, [:title, :locale, :desc, :logo, :favicon, :slug, :homepage]) |> OSS.persist_file(:logo) |> OSS.persist_file(:favicon) diff --git a/lib/groupher_server/cms/models/community.ex b/lib/groupher_server/cms/models/community.ex index 630e383..9fcf651 100644 --- a/lib/groupher_server/cms/models/community.ex +++ b/lib/groupher_server/cms/models/community.ex @@ -27,7 +27,7 @@ defmodule GroupherServer.CMS.Model.Community do @required_fields ~w(title desc user_id logo slug)a # @required_fields ~w(title desc user_id)a - @optional_fields ~w(favicon label geo_info index aka contributes_digest pending locale)a + @optional_fields ~w(favicon label geo_info index aka contributes_digest pending locale homepage)a def max_pinned_article_count_per_thread, do: @max_pinned_article_count_per_thread @@ -44,6 +44,7 @@ defmodule GroupherServer.CMS.Model.Community do field(:geo_info, :map) field(:views, :integer) field(:locale, :string) + field(:homepage, :string) embeds_one(:meta, Embeds.CommunityMeta, on_replace: :delete) belongs_to(:author, User, foreign_key: :user_id) diff --git a/lib/groupher_server/cms/models/metrics/dashboard.ex b/lib/groupher_server/cms/models/metrics/dashboard.ex index ef37d51..7e33db3 100644 --- a/lib/groupher_server/cms/models/metrics/dashboard.ex +++ b/lib/groupher_server/cms/models/metrics/dashboard.ex @@ -30,6 +30,7 @@ defmodule GroupherServer.CMS.Model.Metrics.Dashboard do [ [:favicon, :string, ""], [:title, :string, ""], + [:locale, :string, ""], [:logo, :string, ""], [:slug, :string, ""], [:desc, :string, ""], diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index c14aca1..00784f9 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -182,6 +182,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:desc, :string) field(:slug, :string) field(:favicon, :string) + field(:homepage, :string) field(:index, :integer) field(:logo, :string) field(:author, :user, resolve: dataloader(CMS, :author)) diff --git a/priv/repo/migrations/20240503045538_add_homepage_to_community.exs b/priv/repo/migrations/20240503045538_add_homepage_to_community.exs new file mode 100644 index 0000000..72af294 --- /dev/null +++ b/priv/repo/migrations/20240503045538_add_homepage_to_community.exs @@ -0,0 +1,9 @@ +defmodule GroupherServer.Repo.Migrations.AddHomepageToCommunity do + use Ecto.Migration + + def change do + alter table(:communities, prefix: "cms") do + add(:homepage, :string) + end + end +end diff --git a/test/groupher_server_web/mutation/cms/dashboard_test.exs b/test/groupher_server_web/mutation/cms/dashboard_test.exs index 4adfdf6..c430cb6 100644 --- a/test/groupher_server_web/mutation/cms/dashboard_test.exs +++ b/test/groupher_server_web/mutation/cms/dashboard_test.exs @@ -22,20 +22,23 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do describe "[mutation cms community]" do @update_info_query """ - mutation($community: String!, $homepage: String, $title: String, $slug: String, $desc: String, $introduction: String, $logo: String, $favicon: String, $city: String, $techstack: String) { - updateDashboardBaseInfo(community: $community, homepage: $homepage, title: $title, slug: $slug, desc: $desc, introduction: $introduction, logo: $logo, favicon: $favicon, city: $city, techstack: $techstack) { + mutation($community: String!, $homepage: String, $locale: String, $title: String, $slug: String, $desc: String, $introduction: String, $logo: String, $favicon: String, $city: String, $techstack: String) { + updateDashboardBaseInfo(community: $community, homepage: $homepage, locale: $locale, title: $title, slug: $slug, desc: $desc, introduction: $introduction, logo: $logo, favicon: $favicon, city: $city, techstack: $techstack) { id title + locale dashboard { baseInfo { title + locale introduction } } } } """ + @tag :wip test "update community dashboard base info", ~m(community)a do rule_conn = simu_conn(:user, cms: %{"community.update" => true}) @@ -45,6 +48,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do slug: "groupher", homepage: "https://groupher.com", desc: "thie community is awesome", + locale: "lt", introduction: """ I feel very happy writing this post. After reading this post you might feel the same as me. @@ -74,8 +78,10 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do {:ok, found} = Community |> ORM.find(updated["id"], preload: :dashboard) + assert found.locale == "lt" assert found.dashboard.base_info.introduction |> String.length() == 828 assert found.dashboard.base_info.title == "groupher" + assert found.dashboard.base_info.locale == "lt" assert found.dashboard.base_info.desc == "thie community is awesome" assert found.dashboard.base_info.slug == "groupher"