diff --git a/lib/ext/person.rb b/lib/ext/person.rb index c7a56c2..f246da2 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -12,4 +12,19 @@ class Person # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD false end + + def points_by_type type + categorizations = GamificationPlugin::PointsCategorization.by_type(type) + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } + end + + def points_by_profile profile + categorizations = GamificationPlugin::PointsCategorization.by_profile(profile) + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } + end + + def points_out_of_profiles + categorizations = GamificationPlugin::PointsCategorization.where(profile_id: nil) + categorizations.inject(0) { |sum, c| sum += self.points(category: c.id.to_s) } + end end diff --git a/lib/gamification_plugin/api.rb b/lib/gamification_plugin/api.rb index 5c03435..31b0422 100644 --- a/lib/gamification_plugin/api.rb +++ b/lib/gamification_plugin/api.rb @@ -12,6 +12,15 @@ class GamificationPlugin::API < Grape::API get 'points' do {points: current_person.points} end + get 'points_by_type' do + {points: current_person.points_by_type(params[:type]) } + end + get 'points_by_profile' do + {points: current_person.points_by_profile(params[:profile]) } + end + get 'points_out_of_profiles' do + {points: current_person.points_out_of_profiles } + end end @@ -28,6 +37,24 @@ class GamificationPlugin::API < Grape::API {:points => person.points} end + get ':id/points_by_type' do + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) + return not_found! if person.blank? + {points: person.points_by_type(params[:type]) } + end + + get ':id/points_by_profile' do + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) + return not_found! if person.blank? + {points: person.points_by_type(params[:profile]) } + end + + get ':id/points_out_of_profiles' do + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) + return not_found! if person.blank? + {points: person.points_out_of_profiles } + end + get ':id/level' do person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) return not_found! if person.blank? -- libgit2 0.21.2