Skip to content

Commit

Permalink
refactor: add before_action in puzzles_controller"
Browse files Browse the repository at this point in the history
  • Loading branch information
MelTravelz committed Nov 2, 2023
1 parent b385b8c commit 3f238ec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/controllers/api/v1/puzzles_controller.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 3f238ec

Please sign in to comment.