Method: WinewooUser::Comments::CreateComment#call

Defined in:
lib/winewoo_core/use_cases/winewoo_user/comments/create_comment.rb

#call(winewoo_user, wine_id, vintage_id, comment_params, enable_indexation) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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