|
|
@ -1,8 +1,8 @@
|
|
|
|
class HacksController < ApplicationController
|
|
|
|
class HacksController < ApplicationController
|
|
|
|
before_action :require_login, except: [:index]
|
|
|
|
before_action :require_login, except: [:index]
|
|
|
|
before_action :require_teacher_identity, only: [:create, :edit, :update]
|
|
|
|
before_action :require_teacher_identity, only: [:create, :update_set]
|
|
|
|
before_action :require_auth_identity, only: [:update, :edit, :publish]
|
|
|
|
before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set]
|
|
|
|
before_action :find_hack, only: [:edit, :update, :publish, :start]
|
|
|
|
before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set]
|
|
|
|
|
|
|
|
|
|
|
|
# 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可
|
|
|
|
# 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可
|
|
|
|
def start
|
|
|
|
def start
|
|
|
@ -75,6 +75,20 @@ class HacksController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 更新测试集接口
|
|
|
|
|
|
|
|
def update_set
|
|
|
|
|
|
|
|
set = @hack.hack_sets.find_by(id: params[:id])
|
|
|
|
|
|
|
|
set.update_attributes!(hack_set_params)
|
|
|
|
|
|
|
|
render_ok
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 单独删除测试集
|
|
|
|
|
|
|
|
def delete_set
|
|
|
|
|
|
|
|
set = @hack.hack_sets.find_by(id: params[:id])
|
|
|
|
|
|
|
|
set.destroy!
|
|
|
|
|
|
|
|
render_ok
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 发布功能
|
|
|
|
# 发布功能
|
|
|
|
def publish
|
|
|
|
def publish
|
|
|
|
@hack.update_attribute(:status, 1)
|
|
|
|
@hack.update_attribute(:status, 1)
|
|
|
@ -119,6 +133,10 @@ class HacksController < ApplicationController
|
|
|
|
params.permit(hack_sets: [:input, :output, :position])[:hack_sets]
|
|
|
|
params.permit(hack_sets: [:input, :output, :position])[:hack_sets]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hack_set_params
|
|
|
|
|
|
|
|
params.require(:hack_set).permit(:id, :input, :output, :position)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def hack_code_params
|
|
|
|
def hack_code_params
|
|
|
|
params.require(:hack_codes).permit(:code, :language)
|
|
|
|
params.require(:hack_codes).permit(:code, :language)
|
|
|
|
end
|
|
|
|
end
|
|
|
|