Skip to content

Commit

Permalink
feat(community): add locale
Browse files Browse the repository at this point in the history
  • Loading branch information
mydearxym committed May 6, 2024
1 parent cdf67ff commit 328213c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/delegates/community_crud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion lib/groupher_server/cms/models/community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/groupher_server/cms/models/metrics/dashboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule GroupherServer.CMS.Model.Metrics.Dashboard do
[
[:favicon, :string, ""],
[:title, :string, ""],
[:locale, :string, ""],
[:logo, :string, ""],
[:slug, :string, ""],
[:desc, :string, ""],
Expand Down
1 change: 1 addition & 0 deletions lib/groupher_server_web/schema/cms/cms_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions test/groupher_server_web/mutation/cms/dashboard_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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.
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 328213c

Please sign in to comment.