Skip to content

Commit

Permalink
Merge pull request #70 from WWC-Hackathon-2023/5refactor
Browse files Browse the repository at this point in the history
BE | Refactor `PuzzlesController#index` Endpoint
  • Loading branch information
MelTravelz authored Nov 3, 2023
2 parents b385b8c + 126d9ea commit 0df9a6b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/v1/puzzles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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])
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 0df9a6b

Please sign in to comment.