From cfcbf5acdb8496c4322c29b597afc80367c0673e Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sun, 31 May 2020 15:48:17 +0200 Subject: [PATCH] Ad requirement 4 I have no idea how this requirement shall be implemented at the end, but at first step, the tiss_crawler.rb lib checks if the search_term is an empty string and returns an error msg if found otherwise it returns the result, but appended to 'content' key --- .../crawlers/courses_crawler_controller.rb | 9 ++++++++- .../crawlers/people_crawler_controller.rb | 14 +++++++++++--- .../crawlers/projects_crawler_controller.rb | 9 ++++++++- .../crawlers/theses_crawler_controller.rb | 9 ++++++++- lib/tiss/tiss_crawler.rb | 11 ++++++++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 6708d4b..dc41553 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -7,7 +7,14 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available courses - @courses = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @courses = result[:content] + end end def show_detail diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 5fb3d88..ffb605d 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -6,8 +6,16 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController puts params[:search_context] @host = TissCrawler.host - # TissCrawler performs general search over the available people - @people = TissCrawler.search(params) + result = TissCrawler.search(params) + + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @people = result[:content] + end + end def show_detail @@ -39,7 +47,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController else flash[:alert] = 'Person is already favorited!' end - redirect_back(fallback_location: search) + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end end diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 3992598..605efe2 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -6,7 +6,14 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available projects - @projects = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @projects = result[:content] + end end def show_detail diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 62046ba..711b1a0 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -6,7 +6,14 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available theses - @theses = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @theses = result[:content] + end end def show_detail diff --git a/lib/tiss/tiss_crawler.rb b/lib/tiss/tiss_crawler.rb index 0d04494..17cd662 100644 --- a/lib/tiss/tiss_crawler.rb +++ b/lib/tiss/tiss_crawler.rb @@ -10,10 +10,15 @@ class TissCrawler search_parameter = params[:search_parameter] search_term = params[:search_term].parameterize(separator: '+') url = host + api + '?' + search_parameter + '=' + search_term - puts(url) + puts('generated url:', url) + + if search_term == "" + {'error': 'Dare you try! Empty searches are not allowed!'} + else + response = HTTParty.get(url) + {'content': JSON.parse(response.body)['results']} + end - response = HTTParty.get(url) - JSON.parse(response.body)['results'] end def self.get_details(params)