Skip to content

Commit

Permalink
Add endpoint to search users by skill names
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandromontividiu03 committed Oct 31, 2024
1 parent a1014c3 commit 6f1cd36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/user_skills_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def destroy
head :not_found
end

# GET /user_skills/search?query=:query
def search
return render json: [] if params[:query].blank?
query = params[:query].split(/[\s,]+/).map(&:downcase)
users = UserSkill.joins(:skill).where('LOWER(skills.name) IN (?)', query).pluck(:user_id).uniq
render json: User.where(id: users)
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
resources :user_skills, only: [:index] do
collection do
patch :bulk_update
get :search
end
end
end
Expand Down

0 comments on commit 6f1cd36

Please sign in to comment.