From 7fed11affa63da36bd3561d246fd56d1ba65d882 Mon Sep 17 00:00:00 2001 From: Chris Mears Date: Sat, 30 Oct 2021 21:54:15 -0700 Subject: [PATCH 1/5] feat: Combine param validation, return JSON Allow for multiple error messages and use validation for search endpoints too --- app/controllers/breweries_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/breweries_controller.rb b/app/controllers/breweries_controller.rb index 45d2249..3c7cc75 100644 --- a/app/controllers/breweries_controller.rb +++ b/app/controllers/breweries_controller.rb @@ -150,6 +150,8 @@ def validate_params value.gsub!('_', ' ') unless value.nil? || !value.instance_of?(String) case key + when 'query' + error.push('Search cannot be blank.') if value.empty? when 'by_type' unless BREWERY_TYPES.include?(value) errors.push("Brewery type must include one of these types: #{BREWERY_TYPES}") From 758f9d25dd5f118953fa447725b2eb28f0839b13 Mon Sep 17 00:00:00 2001 From: Chris Mears Date: Sat, 30 Oct 2021 22:18:19 -0700 Subject: [PATCH 2/5] fix: Fix typo --- app/controllers/breweries_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/breweries_controller.rb b/app/controllers/breweries_controller.rb index 3c7cc75..5ca368d 100644 --- a/app/controllers/breweries_controller.rb +++ b/app/controllers/breweries_controller.rb @@ -151,7 +151,7 @@ def validate_params case key when 'query' - error.push('Search cannot be blank.') if value.empty? + errors.push('Search cannot be blank.') if value.empty? when 'by_type' unless BREWERY_TYPES.include?(value) errors.push("Brewery type must include one of these types: #{BREWERY_TYPES}") From 1c80858069b20305b541e2da322e8547412b197c Mon Sep 17 00:00:00 2001 From: Chris Mears Date: Tue, 2 Nov 2021 20:56:39 -0700 Subject: [PATCH 3/5] feat: :fire: Remove unnecessary query param check --- app/controllers/breweries_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/breweries_controller.rb b/app/controllers/breweries_controller.rb index 5ca368d..45d2249 100644 --- a/app/controllers/breweries_controller.rb +++ b/app/controllers/breweries_controller.rb @@ -150,8 +150,6 @@ def validate_params value.gsub!('_', ' ') unless value.nil? || !value.instance_of?(String) case key - when 'query' - errors.push('Search cannot be blank.') if value.empty? when 'by_type' unless BREWERY_TYPES.include?(value) errors.push("Brewery type must include one of these types: #{BREWERY_TYPES}") From 07acfb73d53ba7ad9409595949c678bac41ee747 Mon Sep 17 00:00:00 2001 From: Anthony Laflamme Date: Thu, 16 Mar 2023 22:45:05 -0400 Subject: [PATCH 4/5] Should be proprietOr instead of proprieter (#121) --- config/initializers/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 0fc6043..5160bcb 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -8,7 +8,7 @@ "planning", "bar", "contract", - "proprieter", + "proprietor", "closed" ].freeze From 38fa4798cbe01e1e34d714965d1a578e5ac55f93 Mon Sep 17 00:00:00 2001 From: Chris J Mears Date: Thu, 16 Mar 2023 19:47:17 -0700 Subject: [PATCH 5/5] chore: Rubocop fixes --- config/initializers/constants.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 5160bcb..801e60e 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true -BREWERY_TYPES = [ - "micro", - "nano", - "regional", - "brewpub", - "large", - "planning", - "bar", - "contract", - "proprietor", - "closed" +BREWERY_TYPES = %w[ + micro + nano + regional + brewpub + large + planning + bar + contract + proprietor + closed ].freeze MAX_PER_PAGE = 50