diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb new file mode 100644 index 000000000..091163821 --- /dev/null +++ b/app/controllers/item_banks_controller.rb @@ -0,0 +1,4 @@ +class LibrariesController < ApplicationController + + +end \ No newline at end of file diff --git a/app/models/curriculum.rb b/app/models/curriculum.rb index 6c25a5883..0b78814bc 100644 --- a/app/models/curriculum.rb +++ b/app/models/curriculum.rb @@ -1,2 +1,4 @@ class Curriculum < ApplicationRecord + belongs_to :curriculum_direction + has_many :knowledge_points, dependent: :destroy end diff --git a/app/models/curriculum_direction.rb b/app/models/curriculum_direction.rb new file mode 100644 index 000000000..1c9211559 --- /dev/null +++ b/app/models/curriculum_direction.rb @@ -0,0 +1,4 @@ +class CurriculumDirection < ApplicationRecord + has_many :curriculums + has_many :knowledge_points +end diff --git a/app/models/item_analysis.rb b/app/models/item_analysis.rb new file mode 100644 index 000000000..8f6e71302 --- /dev/null +++ b/app/models/item_analysis.rb @@ -0,0 +1,3 @@ +class ItemAnalysis < ApplicationRecord + belongs_to :item_bank +end diff --git a/app/models/item_bank.rb b/app/models/item_bank.rb new file mode 100644 index 000000000..32c349e34 --- /dev/null +++ b/app/models/item_bank.rb @@ -0,0 +1,13 @@ +class ItemBank < ApplicationRecord + # difficulty: 1 简单 2 适中 3 困难 + # item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程 + enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 } + + belongs_to :curriculum + belongs_to :curriculum_direction + belongs_to :user + + has_one :item_analysis, dependent: :destroy + has_many :item_choices, dependent: :destroy + has_many :item_baskets, dependent: :destroy +end diff --git a/app/models/item_basket.rb b/app/models/item_basket.rb new file mode 100644 index 000000000..d736d9bc0 --- /dev/null +++ b/app/models/item_basket.rb @@ -0,0 +1,4 @@ +class ItemBasket < ApplicationRecord + belongs_to :item_bank + belongs_to :user +end diff --git a/app/models/item_choice.rb b/app/models/item_choice.rb new file mode 100644 index 000000000..ccc35698e --- /dev/null +++ b/app/models/item_choice.rb @@ -0,0 +1,3 @@ +class ItemChoice < ApplicationRecord + belongs_to :item_bank +end diff --git a/app/models/knowledge_point.rb b/app/models/knowledge_point.rb index f5abbb54e..3d75b66a1 100644 --- a/app/models/knowledge_point.rb +++ b/app/models/knowledge_point.rb @@ -1,3 +1,5 @@ class KnowledgePoint < ApplicationRecord + belongs_to :curriculum_direction belongs_to :curriculum + has_many :knowledge_point_containers, dependent: :destroy end diff --git a/config/routes.rb b/config/routes.rb index 2ef60b45f..23e13e3d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,9 @@ Rails.application.routes.draw do end end + resources :item_banks do + end resources :hacks, path: :problems, param: :identifier do diff --git a/db/migrate/20191218070922_create_curriculum_directions.rb b/db/migrate/20191218070922_create_curriculum_directions.rb new file mode 100644 index 000000000..9203aa435 --- /dev/null +++ b/db/migrate/20191218070922_create_curriculum_directions.rb @@ -0,0 +1,9 @@ +class CreateCurriculumDirections < ActiveRecord::Migration[5.2] + def change + create_table :curriculum_directions do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20191217100300_create_curriculums.rb b/db/migrate/20191218071017_create_curriculums.rb similarity index 75% rename from db/migrate/20191217100300_create_curriculums.rb rename to db/migrate/20191218071017_create_curriculums.rb index 10eb516d5..885f2a676 100644 --- a/db/migrate/20191217100300_create_curriculums.rb +++ b/db/migrate/20191218071017_create_curriculums.rb @@ -2,6 +2,7 @@ class CreateCurriculums < ActiveRecord::Migration[5.2] def change create_table :curriculums do |t| t.string :name + t.references :curriculum_direction, index: true t.timestamps end diff --git a/db/migrate/20191217102106_create_knowledge_points.rb b/db/migrate/20191218071111_create_knowledge_points.rb similarity index 63% rename from db/migrate/20191217102106_create_knowledge_points.rb rename to db/migrate/20191218071111_create_knowledge_points.rb index 7e0220c81..2f748d266 100644 --- a/db/migrate/20191217102106_create_knowledge_points.rb +++ b/db/migrate/20191218071111_create_knowledge_points.rb @@ -1,8 +1,9 @@ class CreateKnowledgePoints < ActiveRecord::Migration[5.2] def change create_table :knowledge_points do |t| - t.references :curriculum, foreign_key: true t.string :name + t.references :curriculum_direction, index: true + t.references :curriculum, index: true t.timestamps end diff --git a/db/migrate/20191217102414_create_knowledge_point_containers.rb b/db/migrate/20191218071343_create_knowledge_point_containers.rb similarity index 57% rename from db/migrate/20191217102414_create_knowledge_point_containers.rb rename to db/migrate/20191218071343_create_knowledge_point_containers.rb index 32f92f3e5..0b6944ea7 100644 --- a/db/migrate/20191217102414_create_knowledge_point_containers.rb +++ b/db/migrate/20191218071343_create_knowledge_point_containers.rb @@ -1,11 +1,12 @@ class CreateKnowledgePointContainers < ActiveRecord::Migration[5.2] def change create_table :knowledge_point_containers do |t| + t.references :knowledge_point t.integer :container_id t.string :container_type - t.references :knowledge_point, foreign_key: true t.timestamps end + add_index :knowledge_point_containers, [:knowledge_point_id, :container_id, :container_type], name: "container_index", unique: true end end diff --git a/db/migrate/20191218071553_create_item_banks.rb b/db/migrate/20191218071553_create_item_banks.rb new file mode 100644 index 000000000..848edf236 --- /dev/null +++ b/db/migrate/20191218071553_create_item_banks.rb @@ -0,0 +1,16 @@ +class CreateItemBanks < ActiveRecord::Migration[5.2] + def change + create_table :item_banks do |t| + t.text :name + t.references :curriculum, index: true + t.references :curriculum_direction, index: true + t.integer :item_type + t.integer :difficulty + t.references :user, index: true + t.boolean :public + t.integer :quotes + + t.timestamps + end + end +end diff --git a/db/migrate/20191218072457_create_item_analyses.rb b/db/migrate/20191218072457_create_item_analyses.rb new file mode 100644 index 000000000..ab361822e --- /dev/null +++ b/db/migrate/20191218072457_create_item_analyses.rb @@ -0,0 +1,10 @@ +class CreateItemAnalyses < ActiveRecord::Migration[5.2] + def change + create_table :item_analyses do |t| + t.references :item_bank, index: true + t.text :analysis + + t.timestamps + end + end +end diff --git a/db/migrate/20191218072611_create_item_choices.rb b/db/migrate/20191218072611_create_item_choices.rb new file mode 100644 index 000000000..313897be3 --- /dev/null +++ b/db/migrate/20191218072611_create_item_choices.rb @@ -0,0 +1,11 @@ +class CreateItemChoices < ActiveRecord::Migration[5.2] + def change + create_table :item_choices do |t| + t.references :item_bank, index: true + t.text :choice_text + t.boolean :is_answer + + t.timestamps + end + end +end diff --git a/db/migrate/20191218072647_create_item_baskets.rb b/db/migrate/20191218072647_create_item_baskets.rb new file mode 100644 index 000000000..53689d717 --- /dev/null +++ b/db/migrate/20191218072647_create_item_baskets.rb @@ -0,0 +1,10 @@ +class CreateItemBaskets < ActiveRecord::Migration[5.2] + def change + create_table :item_baskets do |t| + t.references :item_bank, index: true + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/spec/models/curriculum_direction_spec.rb b/spec/models/curriculum_direction_spec.rb new file mode 100644 index 000000000..40cab64ca --- /dev/null +++ b/spec/models/curriculum_direction_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CurriculumDirection, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/item_analysis_spec.rb b/spec/models/item_analysis_spec.rb new file mode 100644 index 000000000..155169289 --- /dev/null +++ b/spec/models/item_analysis_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ItemAnalysis, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/item_bank_spec.rb b/spec/models/item_bank_spec.rb new file mode 100644 index 000000000..a8cc2cffb --- /dev/null +++ b/spec/models/item_bank_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ItemBank, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/item_basket_spec.rb b/spec/models/item_basket_spec.rb new file mode 100644 index 000000000..4cdf7e0ea --- /dev/null +++ b/spec/models/item_basket_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ItemBasket, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/item_choice_spec.rb b/spec/models/item_choice_spec.rb new file mode 100644 index 000000000..ff22a255e --- /dev/null +++ b/spec/models/item_choice_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ItemChoice, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end