diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-01-01 17:49:39 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-01-01 17:49:39 +0100 |
commit | e5bf7d1527491af4663c203ec17697e8855b650f (patch) | |
tree | 09f32d4ab8eecb22f1d4b4262f6e02769e645506 /app/services/tartiflette_scoring_service.rb | |
parent | 4d61303eb58cf32f95052227c3158a392dd23373 (diff) |
Cleaned up scores controller and tartiflette scoring service.
Diffstat (limited to 'app/services/tartiflette_scoring_service.rb')
-rw-r--r-- | app/services/tartiflette_scoring_service.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/app/services/tartiflette_scoring_service.rb b/app/services/tartiflette_scoring_service.rb index 3514eb1..2c12025 100644 --- a/app/services/tartiflette_scoring_service.rb +++ b/app/services/tartiflette_scoring_service.rb @@ -1,24 +1,35 @@ class TartifletteScoringService def self.scored?(tartiflette, session) + session[:scored_tartiflettes] ||= [] session[:scored_tartiflettes]&.include?(tartiflette.id) end def self.mark_as_scored(tartiflette, session) session[:scored_tartiflettes] ||= [] - unless scored?(tartiflette, session) - session[:scored_tartiflettes] << tartiflette.id - end + session[:scored_tartiflettes] << tartiflette.id unless scored?(tartiflette, session) end def self.submit_scores(tartiflette, scores, session) - scores.each do |criterium_id, value| + scores.each do |criterium_id, score_params| Score.create!( + session_id: session.id, tartiflette: tartiflette, scoring_criterium_id: criterium_id, - value: value[:value] + value: score_params[:value] ) end mark_as_scored(tartiflette, session) + rescue ActiveRecord::RecordInvalid => e + raise StandardError, "Failed to create score: #{e.message}" + end + + def self.update_scores(tartiflette, scores, session) + scores.each do |score_id, score_params| + score = tartiflette.scores.find(score_id) + score.update!(value: score_params[:value]) + end + rescue ActiveRecord::RecordInvalid => e + raise StandardError, "Failed to update score: #{e.message}" end def self.average_score(tartiflette) |