From 88783ffede1d223a83087fabad50f92206d8bc49 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:54:17 +0200 Subject: [PATCH] on detail view show stored annotation if available --- .../crawlers/people_crawler_controller.rb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index ffb605d..353433a 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -22,6 +22,10 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:api] = '/api/person/v22/id/' params[:tiss_id] = params[:tiss_id] + if FavoritePerson.exists?(params[:tiss_id]) + @stored_person = FavoritePerson.find(params[:tiss_id]) + end + puts params # TissCrawler fetches the person's detail information @person = TissCrawler.get_details(params) @@ -35,12 +39,12 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController @person = TissCrawler.get_details(params) # create stores the object to the db after creation - favorite_hash = { tiss_id: @person['tiss_id'], - # the user who is currently active - user_id: current_user.id, - first_name: @person['first_name'], - last_name: @person['last_name'], - picture_uri: @person['picture_uri'] } + favorite_hash = {tiss_id: @person['tiss_id'], + # the user who is currently active + user_id: current_user.id, + first_name: @person['first_name'], + last_name: @person['last_name'], + picture_uri: @person['picture_uri']} if FavoritePerson.create(favorite_hash).valid? FavoritePerson.create(favorite_hash) flash[:alert] = 'Person added to your favorites!' @@ -50,4 +54,14 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end + def add_annotation + if FavoritePerson.exists?(params[:id]) + FavoritePerson.update(params[:id], :personal_annotation => params[:body]) + flash[:alert] = 'Annotation stored!' + else + flash[:alert] = 'Person has to be favorited first!' + end + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + end + end