From be6a05124a71842efa97ceb0db720dabe5f8e402 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 19 Oct 2020 03:57:07 -0700 Subject: [PATCH] Add search for Characters --- app/controllers/api/v1/search_controller.rb | 8 ++++++++ config/routes.rb | 1 + 2 files changed, 9 insertions(+) diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb index 9640cef..687aab8 100644 --- a/app/controllers/api/v1/search_controller.rb +++ b/app/controllers/api/v1/search_controller.rb @@ -1,4 +1,12 @@ class Api::V1::SearchController < Api::V1::ApiController + def characters + if params[:query].present? + @characters = Character.search(params[:query]).limit(10) + else + @characters = Character.all + end + end + def weapons if params[:query].present? @weapons = Weapon.search(params[:query]).limit(10) diff --git a/config/routes.rb b/config/routes.rb index c1d0734..9a2592a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,7 @@ Rails.application.routes.draw do post 'check/email', to: 'users#check_email' post 'check/username', to: 'users#check_username' + get 'search/characters', to: 'search#characters' get 'search/weapons', to: 'search#weapons' get 'search/summons', to: 'search#summons'