Class: GfreshPoint::Repository::ActiveRecordRepo
- Inherits:
-
Object
- Object
- GfreshPoint::Repository::ActiveRecordRepo
- Defined in:
- lib/gfresh_point/repository/active_record_repo.rb
Instance Method Summary collapse
- #create_balance(app_id, user_id, point, balance, event_name, origin_id, comment) ⇒ Object
- #fetch_user_points(app_id, user_id, event_names, origin_id) ⇒ Object
- #get_rule_by_event_name(app_id, event_name) ⇒ Object
- #get_user_last_balance(app_id, user_id) ⇒ Object
- #list_rules(app_id) ⇒ Object
- #list_user_points(app_id, user_id, event_name, origin_id) ⇒ Object
- #update_rule_point(app_id, rule_id, point, name) ⇒ Object
Instance Method Details
#create_balance(app_id, user_id, point, balance, event_name, origin_id, comment) ⇒ Object
20 21 22 23 24 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 20 def create_balance(app_id, user_id, point, balance, event_name, origin_id, comment) transaction_protect Balance.create!(app_id: app_id, user_id: user_id, point: point, balance: balance, origin_id: origin_id, event_name: event_name, comment: comment) end |
#fetch_user_points(app_id, user_id, event_names, origin_id) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 37 def fetch_user_points(app_id, user_id, event_names, origin_id) query = Balance.where(app_id: app_id).where(user_id: user_id) query = query.where("event_name in (?)", event_names) unless event_names.blank? query = query.where(origin_id: origin_id) unless origin_id.blank? result = query.where(read_at: nil) return_result = result.to_a result.update_all(read_at: Time.now) return_result end |
#get_rule_by_event_name(app_id, event_name) ⇒ Object
26 27 28 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 26 def get_rule_by_event_name(app_id, event_name) Rule.where(app_id: app_id).where(event_name: event_name).first end |
#get_user_last_balance(app_id, user_id) ⇒ Object
15 16 17 18 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 15 def get_user_last_balance(app_id, user_id) Balance.where(app_id: app_id).where(user_id: user_id). order(created_at: :desc).first end |
#list_rules(app_id) ⇒ Object
7 8 9 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 7 def list_rules(app_id) Rule.where(app_id: app_id) end |
#list_user_points(app_id, user_id, event_name, origin_id) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 30 def list_user_points(app_id, user_id, event_name, origin_id) query = Balance.where(app_id: app_id).where(user_id: user_id) query = query.where(event_name: event_name) if event_name.presence query = query.where(origin_id: origin_id) if origin_id.presence query.order(created_at: :desc) end |
#update_rule_point(app_id, rule_id, point, name) ⇒ Object
11 12 13 |
# File 'lib/gfresh_point/repository/active_record_repo.rb', line 11 def update_rule_point(app_id, rule_id, point, name) Rule.find(rule_id).update!(point: point, name: name) end |