From 19ab3d6914913b9b743465dbdfdc5ed7775edc24 Mon Sep 17 00:00:00 2001 From: Israel Barreto Sant'Anna <ibsa14@inf.ufpr.br> Date: Tue, 3 Oct 2017 20:19:10 -0300 Subject: [PATCH] Changed tag search parameter from id to name --- app/controllers/v1/search_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/search_controller.rb b/app/controllers/v1/search_controller.rb index 824fdef6..4fb41720 100644 --- a/app/controllers/v1/search_controller.rb +++ b/app/controllers/v1/search_controller.rb @@ -44,8 +44,13 @@ class V1::SearchController < ApplicationController # GET v1/search/tag # GET v1/search/tag.json def tag - results = TagSearchService.search(Tag.find(tag_search_params[:id])) - render json: paginate(results) + t = Tag.find_by_name(tag_search_params[:name]) + if t.nil? + render json: {"error": "Tag not found."}, status: :unprocessable_entity + else + results = TagSearchService.search(t) + render json: paginate(results), status: :ok + end end private @@ -60,6 +65,6 @@ class V1::SearchController < ApplicationController end def tag_search_params - params.permit(:page, :results_per_page, :id) + params.permit(:page, :results_per_page, :name) end end -- GitLab