class School::Legacy::SchoolYearsController < ApplicationController
  def index
    data = current_school.school_years.ordered

    render_success :ok, json: data.map { |y| years_props(y) }
  end

  def show
    render_success :ok, json: years_props(current_year)
  end

  private
    def years_props(year)
      {
        id: year.id,
        name: year.name,
        academic_year: year.academic_year,
        current: year.current?,
        start: year.q1_start,
        end: year.end
      }
    end

    def current_year
      @current_year ||= current_school.school_years.find_by(id: params[:id])
    end
end
