class WinewooCore::UseCases::WinewooUser::Comments::CreateComment

Public Class Methods

new(log_params=nil) click to toggle source
Calls superclass method WinewooCore::UseCases::BaseUseCase::new
# File lib/winewoo_core/use_cases/winewoo_user/comments/create_comment.rb, line 4
def initialize(log_params=nil)
  super(WinewooCore.comments_repo.new, log_params)
end

Public Instance Methods

call(winewoo_user, wine_id, vintage_id, comment_params, enable_indexation) { |persisted? ? success: failure| ... } click to toggle source
# File lib/winewoo_core/use_cases/winewoo_user/comments/create_comment.rb, line 9
def call(winewoo_user, wine_id, vintage_id, comment_params, enable_indexation)
  comment = self.repo.create(winewoo_user, wine_id, vintage_id, comment_params)

  if comment
    if comment.persisted?
      log = self.log_repo.create(complete_log_params(comment))
      WinewooCore.feed_repo.new.create(log) if enable_indexation
    end

    yield comment.persisted? ?
      UseCaseResults.success(comment) :
      UseCaseResults.failure(comment.errors)
  else
    yield UseCaseResults.not_found
  end
end

Private Instance Methods

complete_log_params(comment) click to toggle source
# File lib/winewoo_core/use_cases/winewoo_user/comments/create_comment.rb, line 29
def complete_log_params(comment)
  wine = WinewooCore.wines_repo.new.get(comment.wine_id)
  self.log_params.params = {
    "action" => "comment_wine",
    "wine_id" => comment.wine_id,
    "vintage_id" => comment.vintage_id,
    "producer_id" => wine.official? ? wine.producer.id : nil,
    "params" => { "rank" => comment.rank }
  }
  return self.log_params
end