class WinewooCore::UseCases::WinewooUser::Cellar::RemoveCellarEntry

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/cellar/remove_cellar_entry.rb, line 4
def initialize(log_params=nil)
  super(WinewooCore.cellar_repo.new, log_params)
end

Public Instance Methods

call(winewoo_user, entry_id) { |entry ? success: not_found| ... } click to toggle source
# File lib/winewoo_core/use_cases/winewoo_user/cellar/remove_cellar_entry.rb, line 9
def call(winewoo_user, entry_id)
  entry = self.repo.destroy(winewoo_user, entry_id)
  self.log_repo.create(complete_log_params(entry)) if entry

  yield entry ?
    UseCaseResults.success(entry) :
    UseCaseResults.not_found
end

Private Instance Methods

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