json.partial! "commons/success"
json.total_count @topics.total_count
json.topics do
  if params[:group_size].present?
    json.array! @topics.to_a.each_slice(params[:group_size].to_i).to_a.each do |group|
      json.array! group.each do |topic|
        case topic.type
        when "Topic::ActivityForum"
          json.partial! "activity_forum", locals: {activity_forum: topic}
        when "Topic::Banner", "Topic::AppletBanner","Topic::CkBanner"
          json.partial! "banner", locals: {banner: topic}
        when "Topic::Card"
          json.partial! "card", locals: {card: topic}
        when "Topic::Cooperator"
          json.partial! "cooperator", locals: {cooperator: topic}
        when "Topic::Organization"
          json.partial! "organization", locals: {organization: topic}
        when "Topic::ExcellentProject"
          json.partial! "excellent_project", locals: {excellent_project: topic}
        when "Topic::ExperienceForum"
          json.partial! "experience_forum", locals: {experience_forum: topic}
        when "Topic::GlccNews"
          json.partial! "glcc_news", locals: {glcc_news: topic}
        when "Topic::PinnedForum"
          json.partial! "pinned_forum", locals: {pinned_forum: topic}
        when "Topic::FriendlyLink"
          json.partial! "friendly_link", locals: {friendly_link: topic}
        when "Topic::JoinUs"
          json.partial! "join_us", locals: {join_us: topic}
        when 'Topic::TechnicalDiscussion'
          json.partial! 'technical_discussion', locals: {technical_discussion: topic}
        when 'Topic::CkForum', 'Topic::JsForum'
          json.partial! 'ck_js_forum', locals: {ck_js_forum: topic}
        when 'Topic::ServiceTerm'
          json.partial! 'service_term', locals: {service_term: topic}
        else
          json.partial! 'all', locals: {topic: topic}
        end
      end
    end
  else
    json.array! @topics.each do |topic|
      case topic.type
      when "Topic::ActivityForum"
        json.partial! "activity_forum", locals: {activity_forum: topic}
      when "Topic::Banner", "Topic::AppletBanner","Topic::CkBanner"
        json.partial! "banner", locals: {banner: topic}
      when "Topic::Card"
        json.partial! "card", locals: {card: topic}
      when "Topic::Cooperator"
        json.partial! "cooperator", locals: {cooperator: topic}
      when "Topic::Organization"
        json.partial! "organization", locals: {organization: topic}
      when "Topic::School"
        json.partial! "school", locals: {school: topic}
      when "Topic::ExcellentProject"
        json.partial! "excellent_project", locals: {excellent_project: topic}
      when "Topic::ExperienceForum"
        json.partial! "experience_forum", locals: {experience_forum: topic}
      when "Topic::GlccNews"
        json.partial! "glcc_news", locals: {glcc_news: topic}
      when "Topic::PinnedForum"
        json.partial! "pinned_forum", locals: {pinned_forum: topic}
      when "Topic::FriendlyLink"
        json.partial! "friendly_link", locals: {friendly_link: topic}
      when "Topic::JoinUs"
        json.partial! "join_us", locals: {join_us: topic}
      when 'Topic::TechnicalDiscussion'
        json.partial! 'technical_discussion', locals: {technical_discussion: topic}
      when 'Topic::CkForum', 'Topic::JsForum'
        json.partial! 'ck_js_forum', locals: {ck_js_forum: topic}
      when 'Topic::ServiceTerm'
        json.partial! 'service_term', locals: {service_term: topic}
      else
        json.partial! 'all', locals: {topic: topic}
      end
    end
  end
end