yslnewtiku
cxt 5 years ago
parent 5c1b6f7c35
commit 71d5786b24

@ -5,8 +5,21 @@ class ItemBasketsController < ApplicationController
end
def basket_list
@single_questions_count = current_user.item_baskets.where(item_type: "SINGLE").count
@multiple_questions_count = current_user.item_baskets.where(item_type: "MULTIPLE").count
@judgement_questions_count = current_user.item_baskets.where(item_type: "JUDGMENT").count
@completion_questions_count = current_user.item_baskets.where(item_type: "COMPLETION").count
@subjective_questions_count = current_user.item_baskets.where(item_type: "SUBJECTIVE").count
@practical_questions_count = current_user.item_baskets.where(item_type: "PRACTICAL").count
@program_questions_count = current_user.item_baskets.where(item_type: "PROGRAM").count
end
def create
ItemBaskets::SaveItemBasketService.call(current_user, create_params)
render_ok
rescue ApplicationService::Error => ex
render_error(ex.message)
end
def destroy

@ -5,7 +5,7 @@ class ItemBanks::SaveItemForm
validates :repertoire_id, presence: true
validates :sub_repertoire_id, presence: true
validates :item_type, presence: true, inclusion: {in: 0..6}, numericality: { only_integer: true }
validates :item_type, presence: true, inclusion: {in: %W(SINGLE MULTIPLE JUDGMENT COMPLETION SUBJECTIVE PRACTICAL PROGRAM)}
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
validates :name, presence: true, length: { maximum: 1000 }
validates :analysis, length: { maximum: 1000 }
@ -13,7 +13,7 @@ class ItemBanks::SaveItemForm
def validate!
super
return unless errors.blank?
choices.each { |item| SubForm.new(item).validate! } if item_type < 3
choices.each { |item| SubForm.new(item).validate! } if %W(SINGLE MULTIPLE JUDGMENT).include?(item_type)
return unless errors.blank?
if [0, 2].include?(item_type) && choices.pluck(:is_answer).select{|item| item == 1}.length > 1
raise("正确答案只能有一个")

@ -1,14 +1,7 @@
class ItemBank < ApplicationRecord
# difficulty: 1 简单 2 适中 3 困难
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
# item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
# 试卷的问题类型
SINGLE = 0 #单选题
MULTIPLE = 1 #多选题
JUDGMENT = 2 #判断题
COMPLETION = 3 # 填空题
SUBJECTIVE = 4 # 主观题
PRACTICAL = 5 #实训题
PROGRAM = 6 #编程题
belongs_to :user
belongs_to :sub_repertoire

@ -1,4 +1,6 @@
class ItemBasket < ApplicationRecord
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
belongs_to :item_bank
belongs_to :user
end

@ -33,7 +33,7 @@ class ItemBanks::SaveItemService < ApplicationService
end
# 选项的创建
if item.item_type < 3
if %W(SINGLE MULTIPLE JUDGMENT).include?(item.item_type)
old_choices = item.item_choices
new_choices = params[:choices]

@ -0,0 +1,7 @@
json.single_questions_count @single_questions_count
json.multiple_questions_count @multiple_questions_count
json.judgement_questions_count @judgement_questions_count
json.completion_questions_count @completion_questions_count
json.subjective_questions_count @subjective_questions_count
json.practical_questions_count @practical_questions_count
json.program_questions_count @program_questions_count

@ -59,7 +59,9 @@ Rails.application.routes.draw do
end
resources :item_baskets do
collection do
get :basket_list
end
end

Loading…
Cancel
Save