From 4152883f383bb85dd4ce0ed20689aebda2dce5b3 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Wed, 3 Aug 2022 10:33:48 +0530 Subject: [PATCH] chore: Add missing locale info in portal API (#5177) --- .../api/v1/accounts/portals/_portal.json.jbuilder | 10 +++++++++- app/views/api/v1/models/_portal_config.json.jbuilder | 3 +++ .../api/v1/accounts/portals_controller_spec.rb | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 app/views/api/v1/models/_portal_config.json.jbuilder diff --git a/app/views/api/v1/accounts/portals/_portal.json.jbuilder b/app/views/api/v1/accounts/portals/_portal.json.jbuilder index 2f37f0a71..a1a16a647 100644 --- a/app/views/api/v1/accounts/portals/_portal.json.jbuilder +++ b/app/views/api/v1/accounts/portals/_portal.json.jbuilder @@ -7,7 +7,15 @@ json.name portal.name json.page_title portal.page_title json.slug portal.slug json.archived portal.archived -json.config portal.config + +json.config do + json.allowed_locales do + json.array! portal.config['allowed_locales'].each do |locale| + json.partial! 'api/v1/models/portal_config.json.jbuilder', locale: locale, portal: portal + end + end +end + json.logo portal.file_base_data if portal.logo.present? json.portal_members do diff --git a/app/views/api/v1/models/_portal_config.json.jbuilder b/app/views/api/v1/models/_portal_config.json.jbuilder new file mode 100644 index 000000000..38e4fdd50 --- /dev/null +++ b/app/views/api/v1/models/_portal_config.json.jbuilder @@ -0,0 +1,3 @@ +json.code locale +json.articles_count portal.articles.search({ locale: locale }).size +json.categories_count portal.categories.search_by_locale(locale).size diff --git a/spec/controllers/api/v1/accounts/portals_controller_spec.rb b/spec/controllers/api/v1/accounts/portals_controller_spec.rb index 8bc6c86a2..71a4b755d 100644 --- a/spec/controllers/api/v1/accounts/portals_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/portals_controller_spec.rb @@ -115,7 +115,8 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) expect(json_response['name']).to eql(portal_params[:portal][:name]) - expect(json_response['config']).to eql({ 'allowed_locales' => %w[en es], 'default_locale' => 'en' }) + expect(json_response['config']).to eql({ 'allowed_locales' => [{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en' }, + { 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }] }) end it 'archive portal' do