From 40d8b4549bc245e67851a95da85f1be012a3e0ef Mon Sep 17 00:00:00 2001 From: legton <lvs16@inf.ufpr.br> Date: Wed, 13 Mar 2019 11:57:13 -0300 Subject: [PATCH] SCRUM#388: Save searched words (with information of whether they had results) --- app/controllers/v1/search_controller.rb | 8 +++++++- .../20190313143808_add_has_results_column_to_searches.rb | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190313143808_add_has_results_column_to_searches.rb diff --git a/app/controllers/v1/search_controller.rb b/app/controllers/v1/search_controller.rb index dd474e8a..942e79c4 100644 --- a/app/controllers/v1/search_controller.rb +++ b/app/controllers/v1/search_controller.rb @@ -27,7 +27,13 @@ class V1::SearchController < ApplicationController # GET v1/search.json def index search = SearchService.instance(@search, current_user).search - save_search() + if ((search.results).empty?) + @search.has_results = false + save_search() + else + @search.has_results = true + save_search() + end headers['X-Total-Count'] = search.total_count render json: search.results, status: :ok diff --git a/db/migrate/20190313143808_add_has_results_column_to_searches.rb b/db/migrate/20190313143808_add_has_results_column_to_searches.rb new file mode 100644 index 00000000..815b4b21 --- /dev/null +++ b/db/migrate/20190313143808_add_has_results_column_to_searches.rb @@ -0,0 +1,5 @@ +class AddHasResultsColumnToSearches < ActiveRecord::Migration[5.0] + def change + add_column :searches, :has_results, :boolean + end +end -- GitLab