class ServicesAndInformationController < ApplicationController
  def index
    setup_content_item_and_navigation_helpers(service_and_information)
    render :index, locals: {
      service_and_information: service_and_information,
      organisation: service_and_information.organisation,
      grouped_links: grouped_links
    }
  end

private

  def base_path
    "/government/organisations/#{params[:organisation_id]}/services-information"
  end

  def service_and_information
    ServiceAndInformation.find!(base_path)
  end

  def grouped_links
    links_grouper =
      ServicesAndInformationLinksGrouper.new(params[:organisation_id])

    links_grouper.parsed_grouped_links.reject do |group|
      group.title.nil?
    end
  end
end

class ServicesAndInformationController < ApplicationController
  def index
    setup_content_item_and_navigation_helpers(service_and_information)
    render :index, locals: {
      service_and_information: service_and_information,
      organisation: service_and_information.organisation,
      grouped_links: grouped_links
    }
  end

private

  def base_path
    "/government/organisations/#{params[:organisation_id]}/services-information"
  end

  def service_and_information
    @service_and_information ||= ServiceAndInformation.find!(base_path)
  end

  def grouped_links
    links_grouper =
      ServicesAndInformationLinksGrouper.new(params[:organisation_id])

    links_grouper.parsed_grouped_links.reject do |group|
      group.title.nil?
    end
  end
end

Reduce requests for services and information
Reduce requests for services and information

This reduces the number of content store requests required to render a page
in services and information from 3 to 1.

Example URL: https://www.gov.uk/government/organisations/hm-revenue-customs/services-information
