diff --git a/app/models/tutor_time.rb b/app/models/tutor_time.rb new file mode 100644 index 0000000000..81b7151e59 --- /dev/null +++ b/app/models/tutor_time.rb @@ -0,0 +1,12 @@ +class TutorTime < ApplicationRecord + belongs_to :user + belongs_to :task + + validates :user_id, presence: true + validates :task_id, presence: true + validates :time_spent, presence: true, numericality: { greater_than_or_equal_to: 0.0 } + + def time_spent_in_hours + (time_spent.to_f / 60.0).round(2) + end +end diff --git a/db/migrate/20250324073540_create_tutor_times.rb b/db/migrate/20250324073540_create_tutor_times.rb new file mode 100644 index 0000000000..eb0bd81558 --- /dev/null +++ b/db/migrate/20250324073540_create_tutor_times.rb @@ -0,0 +1,10 @@ +class CreateTutorTimes < ActiveRecord::Migration[7.1] + def change + create_table :tutor_times do |t| + t.references :user, null: false, foreign_key: { on_delete: :cascade } + t.references :task, null: false, foreign_key: { on_delete: :cascade } + t.decimal :time_spent, precision: 10, scale: 2, null: false, default: 0.0 + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6daa71ebf1..ab31d55533 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_28_223908) do +ActiveRecord::Schema[7.1].define(version: 2025_03_24_073540) do create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t| t.string "name", null: false t.string "abbreviation", null: false @@ -394,6 +394,16 @@ t.index ["tii_task_similarity_id"], name: "index_tii_submissions_on_tii_task_similarity_id" end + create_table "tutor_times", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.bigint "user_id", null: false + t.bigint "task_id", null: false + t.decimal "time_spent", precision: 10, scale: 2, default: "0.0", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["task_id"], name: "index_tutor_times_on_task_id" + t.index ["user_id"], name: "index_tutor_times_on_user_id" + end + create_table "tutorial_enrolments", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -531,4 +541,6 @@ t.index ["user_id"], name: "index_webcals_on_user_id", unique: true end + add_foreign_key "tutor_times", "tasks", on_delete: :cascade + add_foreign_key "tutor_times", "users", on_delete: :cascade end