Class: GfreshPoint::Usecase::EarnPointUsecase

Inherits:
BaseUsecase
  • Object
show all
Defined in:
lib/gfresh_point/usecase/earn_point_usecase.rb

Instance Attribute Summary

Attributes inherited from BaseUsecase

#repo

Instance Method Summary collapse

Methods inherited from BaseUsecase

#call, #generate_response, #initialize

Constructor Details

This class inherits a constructor from GfreshPoint::Usecase::BaseUsecase

Instance Method Details

#execute(request) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/gfresh_point/usecase/earn_point_usecase.rb', line 4

def execute(request)
  rule = repo.get_rule_by_event_name(request.app_id, request.event_name)
  raise "Rule not exist" if rule.blank?
  last_balance = repo.get_user_last_balance(request.app_id, request.user_id).try(:balance).to_i
  # save balance and rule snapshot
  if rule.point > 0
    repo.create_balance(request.app_id, request.user_id, rule.point, last_balance + rule.point, request.event_name, request.origin_id, request.comment)
  end
end