chore: Update Help Center APIs to accomodate locale (#4515)

This commit is contained in:
Pranav Raj S
2022-04-20 16:00:37 +05:30
committed by GitHub
parent 4f3a271355
commit f2f0d466f2
17 changed files with 114 additions and 57 deletions

View File

@@ -4,6 +4,6 @@ class Api::V1::Accounts::Kbase::BaseController < Api::V1::Accounts::BaseControll
private
def portal
@portal ||= Current.account.kbase_portals.find_by(id: params[:portal_id])
@portal ||= Current.account.kbase_portals.find_by(slug: params[:portal_id])
end
end

View File

@@ -1,10 +1,12 @@
class Api::V1::Accounts::Kbase::PortalsController < Api::V1::Accounts::Kbase::BaseController
class Api::V1::Accounts::Kbase::PortalsController < Api::V1::Accounts::BaseController
before_action :fetch_portal, except: [:index, :create]
def index
@portals = Current.account.kbase_portals
end
def show; end
def create
@portal = Current.account.kbase_portals.create!(portal_params)
end
@@ -21,7 +23,11 @@ class Api::V1::Accounts::Kbase::PortalsController < Api::V1::Accounts::Kbase::Ba
private
def fetch_portal
@portal = current_account.kbase_portals.find(params[:id])
@portal = Current.account.kbase_portals.find_by(slug: permitted_params[:id])
end
def permitted_params
params.permit(:id)
end
def portal_params

View File

@@ -4,6 +4,7 @@
#
# id :bigint not null, primary key
# description :text
# locale :string default("en")
# name :string
# position :integer
# created_at :datetime not null
@@ -11,6 +12,10 @@
# account_id :integer not null
# portal_id :integer not null
#
# Indexes
#
# index_kbase_categories_on_locale_and_account_id (locale,account_id)
#
class Kbase::Category < ApplicationRecord
belongs_to :account
belongs_to :portal

View File

@@ -3,8 +3,8 @@
# Table name: kbase_portals
#
# id :bigint not null, primary key
# account_id :integer not null
# color :string
# config :jsonb
# custom_domain :string
# header_text :text
# homepage_link :string
@@ -13,6 +13,7 @@
# slug :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
#
# Indexes
#
@@ -26,5 +27,5 @@ class Kbase::Portal < ApplicationRecord
validates :account_id, presence: true
validates :name, presence: true
validates :slug, presence: true
validates :slug, presence: true, uniqueness: true
end

View File

@@ -6,3 +6,4 @@ json.homepage_link portal.homepage_link
json.name portal.name
json.page_title portal.page_title
json.slug portal.slug
json.config portal.config

View File

@@ -1,3 +1 @@
json.payload do
json.partial! 'portal', portal: @portal
end
json.partial! 'portal', portal: @portal

View File

@@ -1,3 +1 @@
json.payload do
json.array! @portals, partial: 'portal', as: :portal
end
json.array! @portals, partial: 'portal', as: :portal

View File

@@ -0,0 +1 @@
json.partial! 'portal', portal: @portal

View File

@@ -1,3 +1 @@
json.payload do
json.partial! 'portal', portal: @portal
end
json.partial! 'portal', portal: @portal

View File

@@ -0,0 +1 @@
json.partial! 'portal', portal: @portal

View File

@@ -0,0 +1,5 @@
json.id category.id
json.name category.name
json.locale category.locale
json.description category.description
json.position category.position

View File

@@ -0,0 +1,9 @@
json.id portal.id
json.color portal.color
json.custom_domain portal.custom_domain
json.header_text portal.header_text
json.homepage_link portal.homepage_link
json.name portal.name
json.page_title portal.page_title
json.slug portal.slug
json.config portal.config