Skip to content

Commit

Permalink
Add Item Average Rating
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasUCSB committed Nov 25, 2024
1 parent 44ce11b commit 70997e5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Item < ApplicationRecord
validates :price, presence: true, numericality: { greater_than: 0 }
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 }

def average_rating
ratings.average(:score).to_f.round(2)
end

def sold_out?
remaining_quantity <= 0
end
Expand Down

0 comments on commit 70997e5

Please sign in to comment.