Create TrackedTimeEntry as more general replacement of Attendance to include preparation and review
This commit is contained in:
parent
c706aa2561
commit
a2dfad331b
@ -3,6 +3,8 @@ class Lecture < ApplicationRecord
|
|||||||
has_one :attendance, dependent: :destroy
|
has_one :attendance, dependent: :destroy
|
||||||
has_one :recording, dependent: :nullify
|
has_one :recording, dependent: :nullify
|
||||||
|
|
||||||
|
has_many :tracked_time_entries, dependent: :destroy
|
||||||
|
|
||||||
enum :kind, [
|
enum :kind, [
|
||||||
:lecture,
|
:lecture,
|
||||||
:problems_class,
|
:problems_class,
|
||||||
|
|||||||
13
app/models/tracked_time_entry.rb
Normal file
13
app/models/tracked_time_entry.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class TrackedTimeEntry < ApplicationRecord
|
||||||
|
belongs_to :lecture
|
||||||
|
|
||||||
|
enum :kind, [
|
||||||
|
:concurrent,
|
||||||
|
:catchup
|
||||||
|
]
|
||||||
|
|
||||||
|
def duration
|
||||||
|
toggl_data['time_entries'].sum { |entry| entry['seconds'] }
|
||||||
|
.seconds
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/migrate/20231006200812_create_tracked_time_entries.rb
Normal file
11
db/migrate/20231006200812_create_tracked_time_entries.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class CreateTrackedTimeEntries < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :tracked_time_entries do |t|
|
||||||
|
t.references :lecture, null: false, foreign_key: true
|
||||||
|
t.integer :kind
|
||||||
|
t.jsonb :toggl_data
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
test/fixtures/tracked_time_entries.yml
vendored
Normal file
11
test/fixtures/tracked_time_entries.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
lecture: one
|
||||||
|
kind: 1
|
||||||
|
toggl_data:
|
||||||
|
|
||||||
|
two:
|
||||||
|
lecture: two
|
||||||
|
kind: 1
|
||||||
|
toggl_data:
|
||||||
7
test/models/tracked_time_entry_test.rb
Normal file
7
test/models/tracked_time_entry_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class TrackedTimeEntryTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user