Introduce architettura multi-sport con catalogo, engine scoring e overlay.
Catalogo sport in YAML, board implicito, engine per volley/basket/timed/racket/timer/generic, regia e app Android allineate. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,7 +16,10 @@ module Api
|
||||
end
|
||||
|
||||
def create
|
||||
match = @team.matches.create!(match_params)
|
||||
attrs = match_params.to_h
|
||||
attrs["sport_key"] = @team.sport_key if attrs["sport_key"].blank?
|
||||
normalize_scoring_rules!(attrs)
|
||||
match = @team.matches.create!(attrs)
|
||||
attach_opponent_logo(match)
|
||||
render json: match_json(match), status: :created
|
||||
end
|
||||
@@ -59,11 +62,15 @@ module Api
|
||||
end
|
||||
|
||||
def match_params
|
||||
params.require(:match).permit(
|
||||
:opponent_name, :location, :scheduled_at, :sport, :sets_to_win,
|
||||
:category, :opponent_primary_color,
|
||||
scoring_rules: %i[points_per_set points_deciding_set min_point_lead]
|
||||
p = params.require(:match).permit(
|
||||
:opponent_name, :location, :scheduled_at, :sport, :sport_key, :sets_to_win,
|
||||
:category, :opponent_primary_color, :overlay_kind,
|
||||
scoring_rules: {}
|
||||
)
|
||||
if p[:sport].present? && p[:sport_key].blank?
|
||||
p[:sport_key] = p.delete(:sport)
|
||||
end
|
||||
p
|
||||
end
|
||||
|
||||
def normalize_scoring_rules!(attrs)
|
||||
@@ -71,6 +78,9 @@ module Api
|
||||
|
||||
rules = attrs["scoring_rules"]
|
||||
attrs["scoring_rules"] = {} if rules.blank?
|
||||
if attrs["sets_to_win"].present? && attrs["scoring_rules"].is_a?(Hash)
|
||||
attrs["scoring_rules"]["sets_to_win"] ||= attrs["sets_to_win"]
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_opponent_color!(attrs)
|
||||
@@ -97,9 +107,15 @@ module Api
|
||||
opponent_name: match.opponent_name,
|
||||
location: match.location,
|
||||
scheduled_at: match.scheduled_at,
|
||||
sport: match.sport,
|
||||
sport: match.sport_key,
|
||||
sport_key: match.sport_key,
|
||||
sport_label: match.sport_label,
|
||||
board_type: match.effective_board_type,
|
||||
overlay_kind: match.overlay_kind,
|
||||
effective_overlay_kind: match.effective_overlay_kind,
|
||||
sets_to_win: match.sets_to_win,
|
||||
scoring_rules: match.scoring_rules.presence,
|
||||
effective_scoring_rules: match.effective_scoring_rules,
|
||||
category: match.category,
|
||||
home_primary_color: team.effective_primary_color,
|
||||
home_secondary_color: team.effective_secondary_color,
|
||||
|
||||
Reference in New Issue
Block a user