module Shared::Legacy::ClassroomsScoped
  extend ActiveSupport::Concern

  def index
    render_success :ok, json: classrooms.map { |c| classroom_props(c) }
  end

  private
    def classroom_props(classroom)
      {}.tap do |props|
        props[:id] = classroom.id
        props[:name] = classroom.name
      end
    end

    def classrooms
      current_school.classrooms
        .by_homeroom(params[:homeroom].to_bool)
        .ordered
        .distinct
    end
end
