summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/tartiflette_scoring_service.rb21
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)
Copyright 2019--2025 Marius PETER