Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better comments for stories and tweets models #111

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 15 additions & 12 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@

################ logic #################
# - the `processed` tag is used to determine if the stem has been created by the ai.
# * it is set to true in stories/make_stem_job.rb
# * if it checked against in the process_story_stems_job.rb
# * it is set to true in stories/make_stem_job
# * if it checked against in the process_story_stems_job
#
# - the `invalid_json` tag is set to true if the ai fails to create a stem for the story.
# * it is set to true in stories/make_stem_job.rb
# * it is set to true in stories/make_stem_job
#
# - the `invalid_images` tag is set to true if the ai fails to create images ideas for any of the images.
# * it is set to true in create_image_idea_job.rb
# * it is set to true in create_image_idea_job
#
# - the `approved` is set if the tweet has been approved for publishing
# * it is set to true or false in stories/moderate_story_job
########################################

class Story < ApplicationRecord
Expand All @@ -39,7 +42,7 @@ class Story < ApplicationRecord

belongs_to :sub_topic

# used by the `stories_controller.rb` as a filter
# used by the `stories_controller` as a filter
scope :viewable, lambda {
where(processed: true,
invalid_json: false,
Expand All @@ -51,7 +54,7 @@ class Story < ApplicationRecord

scope :processed, -> { where(processed: true) }

# used by the `create_image_ideas_from_stories_job.rb` to generate image ideas
# used by the `create_image_ideas_from_stories_job` to generate image ideas
scope :without_images, lambda {
joins("LEFT JOIN images ON images.story_id = stories.id")
.where("images.id IS NULL")
Expand All @@ -67,31 +70,31 @@ class Story < ApplicationRecord
.having('count(images.id) = 3')
}

# used by the `process_discussion_stems_job.rb` to create discussions
# used by the `process_discussion_stems_job` to create discussions
# for stories with valid images.
scope :with_stem_and_valid_processed_images_no_discussions, lambda {
with_stem_and_valid_processed_images
.left_joins(:discussion)
.where(discussions: { id: nil })
}

# used by the filtering stories_controller.rb, dashboard on page_controller.rb
# and as a filter moderate_stories_job.rb
# used by the filtering `stories_controller`, dashboard on `page_controller`
# and as a filter `moderate_stories_job`
scope :needs_approval, lambda {
where(approved: nil, invalid_json: false)
}

# used by the filtering `stories_controller.rb` and dashboard on `page_controller.rb`
# used by the filtering `stories_controller` and dashboard on `page_controller`
scope :denied_stories, lambda {
where(approved: false, invalid_json: false)
}

# used by the filtering `stories_controller.rb` and dashboard on `page_controller.rb`
# used by the filtering `stories_controller` and dashboard on `page_controller`
scope :approved_stories, lambda {
where(approved: true, invalid_json: false)
}

# used by the filtering `stories_controller.rb`
# used by the filtering `stories_controller`
scope :published_stories, lambda {
joins(:discussion)
.where(invalid_json: false,
Expand Down
20 changes: 20 additions & 0 deletions app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,36 @@
# created_at :datetime not null
# updated_at :datetime not null
# approved :boolean

################ logic #################
# - the `processed` tag is used to determine if the stem has been created by the ai.
# * it is set to true in tweets/make_stem_job.rb
#
# - the `invalid_json` tag is set to true if the ai fails to create a stem for the discussion.
# * it is set to true in tweets/make_stem_job.rb
#
# - the `uploaded` tag is used to determine if the discussion has been uploaded to StoryPRO
# * it is set to true in publish_tweet_job.rb
#
# - the `published_at` tag is the date when the item was published to StoryPRO
# * it is set to true in publish_tweet_job.rb
#
# - the `approved` is set if the tweet has been approved for publishing
# * it is set to true or false in tweets_controller.rb
########################################

class Tweet < ApplicationRecord
belongs_to :discussion

# used by `tweets_controller` for filtering and `page_controller` for dashboard logic
scope :needs_approval, -> { where(approved: nil, uploaded: false) }

# used by `tweets_controller` for filtering and `page_controller` for dashboard logic
scope :approved_tweets, -> { where(approved: true) }

# used by `tweets_controller` for filtering and `page_controller` for dashboard logic
scope :denied, -> { where(approved: false) }

# used by `tweets_controller` for filtering and `page_controller` for dashboard logic
scope :published, -> { where(uploaded: true) }
end