diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 655fea471..ff0af5958 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -1,9 +1,9 @@ class HackUserLastestCodesController < ApplicationController before_action :require_login, except: [:listen_result] - before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, + before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, :add_notes, :listen_result, :result, :submit_records, :restore_initial_code] before_action :update_user_hack_status, only: [:code_debug, :code_submit] - #before_action :require_auth_identity, only: [:restore_initial_code, :sync_code] + before_action :require_auth_identity, only: [:add_notes] before_action :require_manager_identity, only: [:show, :update_code, :restore_initial_code, :sync_code] def show @@ -67,7 +67,6 @@ class HackUserLastestCodesController < ApplicationController end - # 提交记录详情 def record_detail @hack_user = HackUserCode.find params[:id] @@ -109,6 +108,11 @@ class HackUserLastestCodesController < ApplicationController end + def add_notes + @my_hack.update_attribute(:notes, params[:notes]) + render_ok + end + private def find_my_hack @my_hack = HackUserLastestCode.find_by(identifier: params[:identifier]) diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 830f16dde..99582af41 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -12,4 +12,6 @@ class HackUserLastestCode < ApplicationRecord scope :mine_hack, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} + validates_length_of :notes, maximum: 5000, message: "笔记不能超过5000个字" + end diff --git a/app/views/hack_user_lastest_codes/show.json.jbuilder b/app/views/hack_user_lastest_codes/show.json.jbuilder index 098c24546..a158d074f 100644 --- a/app/views/hack_user_lastest_codes/show.json.jbuilder +++ b/app/views/hack_user_lastest_codes/show.json.jbuilder @@ -5,6 +5,7 @@ json.hack do json.code @my_hack.code json.pass_count @hack.pass_num json.submit_count @hack.submit_num + json.notes @my_hack.notes json.modify_code @modify json.comments_count @hack.discusses.count json.user_praise @hack.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 diff --git a/config/routes.rb b/config/routes.rb index 7a68ed5e2..f9ed12dbe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,6 +90,7 @@ Rails.application.routes.draw do get :submit_records post :restore_initial_code post :sync_code + post :add_notes end collection do diff --git a/db/migrate/20191226083915_add_notes_hack_user_lastest_codes.rb b/db/migrate/20191226083915_add_notes_hack_user_lastest_codes.rb new file mode 100644 index 000000000..518e6d610 --- /dev/null +++ b/db/migrate/20191226083915_add_notes_hack_user_lastest_codes.rb @@ -0,0 +1,5 @@ +class AddNotesHackUserLastestCodes < ActiveRecord::Migration[5.2] + def change + add_column :hack_user_lastest_codes, :notes, :longtext + end +end