From 3f238ec93861400d49529614db610380e75b1c5e Mon Sep 17 00:00:00 2001 From: Melony Franchini Date: Thu, 2 Nov 2023 12:10:39 -0600 Subject: [PATCH 1/2] refactor: add before_action in puzzles_controller" --- app/controllers/api/v1/puzzles_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/puzzles_controller.rb b/app/controllers/api/v1/puzzles_controller.rb index 3ba2337..ca6125a 100644 --- a/app/controllers/api/v1/puzzles_controller.rb +++ b/app/controllers/api/v1/puzzles_controller.rb @@ -1,16 +1,17 @@ class Api::V1::PuzzlesController < ApplicationController skip_before_action :set_current_user, only: [:index] + before_action :find_puzzles, only: [:index] def index - find_puzzles(params[:zip_code]) + # find_puzzles(params[:zip_code]) raise NoPuzzlesFoundException if @puzzles_in_zip_code.empty? render json: PuzzleSerializer.new(@puzzles_in_zip_code) end private - def find_puzzles(zip_code) - @puzzles_in_zip_code = Puzzle.find_by_zip_code(zip_code) + def find_puzzles + @puzzles_in_zip_code = Puzzle.find_by_zip_code(params[:zip_code]) end end From 126d9ea8b62a4adde149aa3bf091ae11140e1683 Mon Sep 17 00:00:00 2001 From: Melony Franchini Date: Thu, 2 Nov 2023 12:10:59 -0600 Subject: [PATCH 2/2] fix: remove commented out line' --- app/controllers/api/v1/puzzles_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/v1/puzzles_controller.rb b/app/controllers/api/v1/puzzles_controller.rb index ca6125a..4e5507b 100644 --- a/app/controllers/api/v1/puzzles_controller.rb +++ b/app/controllers/api/v1/puzzles_controller.rb @@ -3,7 +3,6 @@ class Api::V1::PuzzlesController < ApplicationController before_action :find_puzzles, only: [:index] def index - # find_puzzles(params[:zip_code]) raise NoPuzzlesFoundException if @puzzles_in_zip_code.empty? render json: PuzzleSerializer.new(@puzzles_in_zip_code) end