module V1
  module Entities
    class Category < Grape::Entity
      expose :title, documentation: {type: 'String', desc: "类别标题"},as: :category
      expose :id, documentation: {type: 'Integer', desc: "类别id"}, as: :cid
      expose :cover_url, documentation:{type: 'String', desc: "封面图地址"}
      expose :years, as: :list_by_year, using: V1::Entities::Year
      expose :chapters, as: :list_by_chapter, using: V1::Entities::Chapter
      # expose :list_by_year do |instance, options|
      #   V1::Entities::Year.represent options[:years]
      # end
      # expose :list_by_chapter do |instance, options|
      #   V1::Entities::Chapter.represent options[:chapters]
      # end
    end
  end
end


module V1
  module Entities
    class Subject < Grape::Entity
      root "data"
      expose :title, documentation: {type: 'String', desc: "科目标题"}, as: :subject
      expose :id, documentation: {type: 'String', desc: "科目id"}, as: :sid

      expose :categories, using: V1::Entities::Category, safe: true
    end
  end
end


      get 'menu' do
        authenticate!
        subjects = Subject.all()
        # years = Year.all()
        # chapters = Chapter.all()
        present subjects, with: V1::Entities::Subject # , years: years, chapters: chapters
      end