class GfreshPoint::Repository::ActiveRecordRepo
Public Instance Methods
create_balance(app_id, user_id, point, balance, event_name, origin_id, comment)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
is_in_transcation?()
click to toggle source
# File lib/gfresh_point/repository/active_record_repo.rb, line 49 def is_in_transcation? !(ActiveRecord::Base.connection.open_transactions == 0) end
transaction_protect()
click to toggle source
# File lib/gfresh_point/repository/active_record_repo.rb, line 53 def transaction_protect unless is_in_transcation? raise "Point operation must be in a transaction " end end