Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/models/tutor_time.rb
Original file line number Diff line number Diff line change
@@ -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 }

def time_spent_in_hours
time_spent.to_f / 60
end
end
10 changes: 10 additions & 0 deletions db/migrate/20250324073540_create_tutor_times.rb
Original file line number Diff line number Diff line change
@@ -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: true
t.references :task, null: false, foreign_key: true
t.integer :time_spent, null: false, default: 0
t.timestamps
end
end
end
14 changes: 13 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.integer "time_spent", default: 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
Expand Down Expand Up @@ -531,4 +541,6 @@
t.index ["user_id"], name: "index_webcals_on_user_id", unique: true
end

add_foreign_key "tutor_times", "tasks"
add_foreign_key "tutor_times", "users"
end