diff --git a/app/controllers/dice_rolls_controller.rb b/app/controllers/dice_rolls_controller.rb index 860c5ac..fd825e5 100644 --- a/app/controllers/dice_rolls_controller.rb +++ b/app/controllers/dice_rolls_controller.rb @@ -2,7 +2,10 @@ class DiceRollsController < ApplicationController VALID_DICE_TYPES = %w[d2 d4 d6 d8 d10 d20 d100] def rolls - rolls_count = 1 + # si c'est pas un nombre, to_i renverra 0 + requested_rolls_count = params[:rolls_count].to_i + # si le nombre de dés demandé est pas supérieur à 0, on utilise 1 comme valeur par défaut + rolls_count = (requested_rolls_count > 0) ? requested_rolls_count : 1 unless VALID_DICE_TYPES.include?(params[:dice_type]) render json: {}, status: 404 diff --git a/config/routes.rb b/config/routes.rb index 9e63256..781608c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html - get '/dice-rolls/:dice_type', to: "dice_rolls#rolls" + get '/dice-rolls/:dice_type/(:rolls_count)', to: "dice_rolls#rolls" # Defines the root path route ("/") root 'home#welcome'