tiss2go/app/controllers/crawlers/people_crawler_controller.rb
Pfingstfrosch 9dcb2994e1 create a hash of favorite details and reuse it;
move redirect_back out of conditional scope
2020-05-16 11:58:25 +02:00

44 lines
1.3 KiB
Ruby

class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
def show_basic
params[:api] = '/api/person/v22/psuche'
params[:search_parameter] = 'q'
puts params[:search_context]
@host = TissCrawler.get_host
# TissCrawler performs general search over the available people
@people = TissCrawler.search(params)
end
def show_detail
params[:api] = '/api/person/v22/id/'
params[:tiss_id] = params[:tiss_id]
puts params
# TissCrawler fetches the person's detail information
@person = TissCrawler.get_details(params)
# Host is needed for image rendering
@host = TissCrawler.get_host
end
def add_to_fav
params[:api] = '/api/person/v22/id/'
puts params[:tiss_id]
@person = TissCrawler.get_details(params)
# create stores the object to the db after creation
favorite_hash = { tiss_id: @person['tiss_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!'
else
flash[:alert] = 'Person is already favorited!'
end
redirect_back(fallback_location: search)
end
end