From 5279102f0be8984d27500cea96bf09d35624426b Mon Sep 17 00:00:00 2001 From: Melony Franchini Date: Sun, 29 Oct 2023 11:36:21 -0600 Subject: [PATCH] refactor: Puzzles#index action Oh YEA ' --- app/controllers/api/v1/puzzles_controller.rb | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/puzzles_controller.rb b/app/controllers/api/v1/puzzles_controller.rb index 6a448a7..0120dc7 100644 --- a/app/controllers/api/v1/puzzles_controller.rb +++ b/app/controllers/api/v1/puzzles_controller.rb @@ -2,12 +2,24 @@ class Api::V1::PuzzlesController < ApplicationController skip_before_action :set_current_user, only: [:index] def index - puzzles_in_zip_code = Puzzle.find_by_zip_code(params[:zip_code]) + find_puzzles(params[:zip_code]) + raise NoPuzzlesException if @puzzles_in_zip_code.empty? + render json: PuzzleSerializer.new(@puzzles_in_zip_code) + end + + private - if puzzles_in_zip_code.any? - render json: PuzzleSerializer.new(puzzles_in_zip_code) - else - raise NoPuzzlesException - end + def find_puzzles(zip_code) + @puzzles_in_zip_code = Puzzle.find_by_zip_code(zip_code) end end + +# Note to self: Saving this to remember process that lead me to final version: +#def index + # puzzles_in_zip_code = Puzzle.find_by_zip_code(params[:zip_code]) + # if @puzzles_in_zip_code.any? + # render json: PuzzleSerializer.new(@puzzles_in_zip_code) + # else + # raise NoPuzzlesException + # end +# end \ No newline at end of file