Class: WinewooUser::Favorites::CreateFavorite

Inherits:
BaseUseCase
  • Object
show all
Defined in:
lib/winewoo_core/use_cases/winewoo_user/favorites/create_favorite.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_params = nil) ⇒ CreateFavorite

Returns a new instance of CreateFavorite.



4
5
6
# File 'lib/winewoo_core/use_cases/winewoo_user/favorites/create_favorite.rb', line 4

def initialize(log_params=nil)
  super(WinewooCore.favorites_repo.new, log_params)
end

Instance Method Details

#call(winewoo_user, favorite_params) {|favorite.persisted? ? UseCaseResults.success(favorite) : UseCaseResults.failure(favorite.errors)| ... } ⇒ Object

Yields:



9
10
11
12
13
14
15
16
17
# File 'lib/winewoo_core/use_cases/winewoo_user/favorites/create_favorite.rb', line 9

def call(winewoo_user, favorite_params)
  favorite = self.repo.create(winewoo_user, favorite_params)

  self.log_repo.create(complete_log_params(favorite)) if favorite.persisted?

  yield favorite.persisted? ?
    UseCaseResults.success(favorite) :
    UseCaseResults.failure(favorite.errors)
end