class Api::TracksController < Api::ApplicationController
  load_and_authorize_resource :release
  before_action :retrieve_tracks, only: :index

  load_and_authorize_resource :track, through: :release, shallow: true
  before_action :prepare_tracks, only: :index

protected

  def retrieve_tracks
    @release.musicbrainz.retrieve_tracks if @release && @release.musicbrainz_uid?
  end

  def prepare_tracks
    @tracks = @tracks.page(params[:page]).order(:disc_number, :track_number)
  end
end
