class WinewooCore::Repositories::ElasticSearch::FeedElasticRepo

Public Instance Methods

create(user_log) click to toggle source
# File lib/winewoo_core/repositories/elastic_search/feed_elastic_repo.rb, line 14
def create(user_log)
  elastic_services = WinewooCore::Services::ElasticSearch::NewsServices.new
  elastic_services.post_news(news_entry_from_log(user_log))
end
find(filters, with_error) click to toggle source
# File lib/winewoo_core/repositories/elastic_search/feed_elastic_repo.rb, line 5
def find(filters, with_error)
  page = (filters.page || 1).to_i
  per_page = (filters.per_page || Kaminari::config.default_per_page).to_i

  elastic_services = WinewooCore::Services::ElasticSearch::NewsServices.new(with_error)
  elastic_services.fetch_news(page - 1, per_page)
end

Private Instance Methods

comment_feed_message(wine, vintage) click to toggle source
# File lib/winewoo_core/repositories/elastic_search/feed_elastic_repo.rb, line 29
def comment_feed_message(wine, vintage)
  wine_name = wine.name
  wine_name += " - #{vintage.title}" unless vintage.title == "Base"
  "Un nouveau commentaire de dégustation pour le vin #{wine_name}."
end
news_entry_from_log(user_log) click to toggle source
# File lib/winewoo_core/repositories/elastic_search/feed_elastic_repo.rb, line 36
def news_entry_from_log(user_log)
  type = user_log.action == "comment_wine" ? :comment : :scan
  wine = Wine.find(user_log.wine_id)
  vintage = wine.vintages.find(user_log.vintage_id)
  text = type == :comment ? comment_feed_message(wine, vintage) :
    scan_feed_message(wine, vintage)
  WinewooCore::Models::NewsEntry.new.tap do |entry|
    entry.type = type
    entry.text = text
    entry.media = wine.official? ? vintage.wine_label.thumb.url : nil
    entry.wine_id = wine.id.to_s
    entry.vintage_id = vintage.id.to_s
    entry.created_at = user_log.action_date
    entry.wine_name = wine.name
    entry.vintage_title = vintage.title
  end
end
scan_feed_message(wine, vintage) click to toggle source
# File lib/winewoo_core/repositories/elastic_search/feed_elastic_repo.rb, line 22
def scan_feed_message(wine, vintage)
  wine_name = wine.name
  wine_name += " - #{vintage.title}" unless vintage.title == "Base"
  "Le vin #{wine_name} a été scanné."
end