class Admins::ImportCompetitionScoresController < Admins::BaseController
  def create
    return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)

    result = Admins::ImportCompetitionScoreService.call(params[:file].to_io, current_competition)
    render_ok(result)
  rescue Admins::ImportCompetitionScoreService::Error => ex
    render_error(ex)
  end

  def current_competition
    competition = Competition.find_by!(id: params[:competition_id])
  end
end