You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
class ItemBasketsController < ApplicationController
|
|
|
|
before_action :require_login
|
|
|
|
|
|
|
|
def index
|
|
|
|
@item_baskets = current_user.item_baskets
|
|
|
|
@single_questions = @item_baskets.where(item_type: "SINGLE")
|
|
|
|
@multiple_questions = @item_baskets.where(item_type: "MULTIPLE")
|
|
|
|
@judgement_questions = @item_baskets.where(item_type: "JUDGMENT")
|
|
|
|
@program_questions = @item_baskets.where(item_type: "PROGRAM")
|
|
|
|
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
|
|
|
|
item = current_user.item_baskets.find_by!(item_bank_id: params[:id])
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
current_user.item_baskets.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
|
|
|
|
item.destroy!
|
|
|
|
end
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_item_type
|
|
|
|
baskets = ItemBasket.where(item_type: params[:item_type])
|
|
|
|
baskets.destroy_all
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_params
|
|
|
|
params.permit(item_ids: [])
|
|
|
|
end
|
|
|
|
end
|