Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmsmith committed Aug 27, 2023
1 parent 9b2e04c commit 8ad9b39
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 9 deletions.
23 changes: 16 additions & 7 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ class Relationship < ApplicationRecord
belongs_to :section
has_one :review, dependent: :restrict_with_exception

enum stored_status: {
planned: "planned",
subscribed: "subscribed",
enrolled: "enrolled",
}

class Status < T::Enum
enums do
Planned = new
Subscribed = new
Enrolled = new
# A relationship can be in one of the following states:
Planned = new("planned") # A user has put this section into their class plan for a quarter
Subscribed = new("subscribed") # The section is in a class plan and the user wants enrollment notifications for the section
Enrolled = new("enrolled") # The section has been enrolled in. No need to send further notifications.

Completed = new("completed") # Where enrolled sections go after the quarter ends. The user has taken the course!
Reviewed = new("reviewed") # The user has taken the section and reviewed it.

Completed = new
Reviewed = new
# How does Status differ from stored_status above? We track the first three states (planned, subscribed, enrolled) in the database on this relationship model. The other two states (completed, reviewed) are derived based off other information (term calendar and if a review was written, respectively).
end
end

Expand All @@ -25,8 +34,8 @@ def status
Status::Reviewed
elsif completed?
Status::Completed
# else
# current_status
else
Status.deserialize(stored_status)
end
end

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20230827154404_track_relationship_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def change

change_table(:relationships, bulk: true) do |t|
# Will make this non-null in a future migration
t.column(:status, :relationship_status)
t.column(:stored_status, :relationship_status)
end
end
end
2 changes: 1 addition & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ CREATE TABLE public.relationships (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
notify boolean DEFAULT false NOT NULL,
status public.relationship_status
stored_status public.relationship_status
);


Expand Down
119 changes: 119 additions & 0 deletions sorbet/rbi/dsl/relationship.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ad9b39

Please sign in to comment.