Add Elo rating system with match entry and CSV upload
- Implement EloCalculator service for 2v2 Euchre matches - Create background job processing with GoodJob - Add single match entry form - Add CSV upload for batch match entry - Create player rankings view - Add database schema for matches and elo snapshots
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Admin
|
||||
module Matches
|
||||
class Create < EuchreCamp::Action
|
||||
include Deps[repo: 'repositories.matches']
|
||||
|
||||
def handle(request, response)
|
||||
match_params = request.params.to_h
|
||||
match_params[:played_at] = Time.parse(match_params[:played_at]) if match_params[:played_at]
|
||||
|
||||
# Create the match
|
||||
match = repo.create(match_params)
|
||||
|
||||
# Enqueue background job to calculate Elo
|
||||
EuchreCamp::Jobs::CalculateEloJob.perform_later(match[:id])
|
||||
|
||||
response.redirect_to("/admin/matches")
|
||||
rescue StandardError => e
|
||||
# Handle validation errors or other issues
|
||||
puts "Error: #{e.message}"
|
||||
puts e.backtrace.join("\n")
|
||||
response.redirect_to("/admin/matches/new")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user