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
54 lines
1.6 KiB
Ruby
54 lines
1.6 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.host
|
|
|
|
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
|
|
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.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'],
|
|
# 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!'
|
|
else
|
|
flash[:alert] = 'Person is already favorited!'
|
|
end
|
|
redirect_back(fallback_location: crawlers_tiss_crawler_search_path)
|
|
end
|
|
|
|
end
|