Commit 64cae55bd92e700dbf34c21c003973c6c2333e6b
1 parent
d05742c0
Exists in
master
and in
1 other branch
Add endpoints for points by type, profile and others
Showing
2 changed files
with
42 additions
and
0 deletions
Show diff stats
lib/ext/person.rb
@@ -12,4 +12,19 @@ class Person | @@ -12,4 +12,19 @@ class Person | ||
12 | # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD | 12 | # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD |
13 | false | 13 | false |
14 | end | 14 | end |
15 | + | ||
16 | + def points_by_type type | ||
17 | + categorizations = GamificationPlugin::PointsCategorization.by_type(type) | ||
18 | + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } | ||
19 | + end | ||
20 | + | ||
21 | + def points_by_profile profile | ||
22 | + categorizations = GamificationPlugin::PointsCategorization.by_profile(profile) | ||
23 | + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } | ||
24 | + end | ||
25 | + | ||
26 | + def points_out_of_profiles | ||
27 | + categorizations = GamificationPlugin::PointsCategorization.where(profile_id: nil) | ||
28 | + categorizations.inject(0) { |sum, c| sum += self.points(category: c.id.to_s) } | ||
29 | + end | ||
15 | end | 30 | end |
lib/gamification_plugin/api.rb
@@ -12,6 +12,15 @@ class GamificationPlugin::API < Grape::API | @@ -12,6 +12,15 @@ class GamificationPlugin::API < Grape::API | ||
12 | get 'points' do | 12 | get 'points' do |
13 | {points: current_person.points} | 13 | {points: current_person.points} |
14 | end | 14 | end |
15 | + get 'points_by_type' do | ||
16 | + {points: current_person.points_by_type(params[:type]) } | ||
17 | + end | ||
18 | + get 'points_by_profile' do | ||
19 | + {points: current_person.points_by_profile(params[:profile]) } | ||
20 | + end | ||
21 | + get 'points_out_of_profiles' do | ||
22 | + {points: current_person.points_out_of_profiles } | ||
23 | + end | ||
15 | 24 | ||
16 | end | 25 | end |
17 | 26 | ||
@@ -28,6 +37,24 @@ class GamificationPlugin::API < Grape::API | @@ -28,6 +37,24 @@ class GamificationPlugin::API < Grape::API | ||
28 | {:points => person.points} | 37 | {:points => person.points} |
29 | end | 38 | end |
30 | 39 | ||
40 | + get ':id/points_by_type' do | ||
41 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
42 | + return not_found! if person.blank? | ||
43 | + {points: person.points_by_type(params[:type]) } | ||
44 | + end | ||
45 | + | ||
46 | + get ':id/points_by_profile' do | ||
47 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
48 | + return not_found! if person.blank? | ||
49 | + {points: person.points_by_type(params[:profile]) } | ||
50 | + end | ||
51 | + | ||
52 | + get ':id/points_out_of_profiles' do | ||
53 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
54 | + return not_found! if person.blank? | ||
55 | + {points: person.points_out_of_profiles } | ||
56 | + end | ||
57 | + | ||
31 | get ':id/level' do | 58 | get ':id/level' do |
32 | person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | 59 | person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) |
33 | return not_found! if person.blank? | 60 | return not_found! if person.blank? |