diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 657ad0f2a..cab952a04 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -1,8 +1,8 @@ class HacksController < ApplicationController before_action :require_login, except: [:index] - before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set, :destroy] + before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set, :destroy, :cancel_publish] before_action :require_teacher_identity, only: [:create] - before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set, :destroy] + before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set, :destroy, :cancel_publish] # 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可 @@ -99,6 +99,12 @@ class HacksController < ApplicationController render_ok end + # 取消发布 + def cancel_publish + @hack.update_attribute(:status, 0) + render_ok + end + # 发布列表 def unpulished_list limit = params[:limit] || 16 diff --git a/app/views/hack_user_lastest_codes/show.json.jbuilder b/app/views/hack_user_lastest_codes/show.json.jbuilder index 2d7ffd2bf..cfdc87d25 100644 --- a/app/views/hack_user_lastest_codes/show.json.jbuilder +++ b/app/views/hack_user_lastest_codes/show.json.jbuilder @@ -1,5 +1,5 @@ json.hack do - json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier) + json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier, :status) json.language @hack.language json.username @hack.user.real_name json.code @my_hack.code diff --git a/app/views/hacks/index.json.jbuilder b/app/views/hacks/index.json.jbuilder index c86884a41..2b4a8b8c7 100644 --- a/app/views/hacks/index.json.jbuilder +++ b/app/views/hacks/index.json.jbuilder @@ -8,6 +8,6 @@ end json.hacks_count @hacks_count json.hacks_list do json.array! @hacks do |hack| - json.(hack,:identifier, :name , :hack_user_lastest_codes_count, :difficult, :passed_rate, :category) + json.(hack,:identifier, :name , :hack_user_lastest_codes_count, :difficult, :passed_rate, :category, :open_or_not, :status) end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0e56141b0..4203df43a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,7 @@ Rails.application.routes.draw do end member do post :publish + post :cancel_publish get :start post :update_set delete :delete_set