@@ -52,6 +52,115 @@ class LeaderboardController @Inject() (
52
52
}
53
53
}
54
54
55
+ /**
56
+ * Gets the top scoring users, based on task completion, over the given
57
+ * number of months (or using start and end dates). Included with each user is their top challenges
58
+ * (by amount of activity).
59
+ *
60
+ * @param id the ID of the challenge
61
+ * @param monthDuration the number of months to consider for the leaderboard
62
+ * @param limit the limit on the number of users returned
63
+ * @param offset the number of users to skip before starting to return results (for pagination)
64
+ * @return Top-ranked users with scores based on task completion activity
65
+ */
66
+ def getChallengeLeaderboard (
67
+ id : Int ,
68
+ monthDuration : Int ,
69
+ limit : Int ,
70
+ offset : Int
71
+ ): Action [AnyContent ] = Action .async { implicit request =>
72
+ this .sessionManager.userAwareRequest { implicit user =>
73
+ Ok (Json .toJson(this .service.getChallengeLeaderboard(id, monthDuration, limit, offset)))
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Gets the leaderboard ranking for a user on a challenge, based on task completion, over
79
+ * the given number of months (or start and end dates). Included with the user is their top challenges
80
+ * (by amount of activity). Also a bracketing number of users above and below
81
+ * the user in the rankings.
82
+ *
83
+ * @param userId user Id for user
84
+ * @param bracket the number of users to return above and below the given user (0 returns just the user)
85
+ * @return User with score and ranking based on task completion activity
86
+ */
87
+ def getChallengeLeaderboardForUser (
88
+ userId : Int ,
89
+ challengeId : Int ,
90
+ monthDuration : Int ,
91
+ bracket : Int
92
+ ): Action [AnyContent ] = Action .async { implicit request =>
93
+ this .sessionManager.userAwareRequest { implicit user =>
94
+ SearchParameters .withSearch { implicit params =>
95
+ Ok (
96
+ Json .toJson(
97
+ this .service.getChallengeLeaderboardForUser(
98
+ userId,
99
+ challengeId,
100
+ monthDuration,
101
+ bracket
102
+ )
103
+ )
104
+ )
105
+ }
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Gets the top scoring users for a specific project, based on task completion,
111
+ * over the given number of months. Included with each user is their score
112
+ * and ranking within the project.
113
+ *
114
+ * @param id the ID of the project
115
+ * @param monthDuration the number of months to consider for the leaderboard
116
+ * @param limit the maximum number of users to return
117
+ * @param offset the number of users to skip before starting to return results (for pagination)
118
+ * @return List of top-ranked users with scores and rankings for the specified project
119
+ */
120
+ def getProjectLeaderboard (
121
+ id : Int ,
122
+ monthDuration : Int ,
123
+ limit : Int ,
124
+ offset : Int
125
+ ): Action [AnyContent ] = Action .async { implicit request =>
126
+ this .sessionManager.userAwareRequest { implicit user =>
127
+ Ok (Json .toJson(this .service.getProjectLeaderboard(id, monthDuration, limit, offset)))
128
+ }
129
+ }
130
+
131
+ // TODO: make this work for projects
132
+ /**
133
+ * Gets the leaderboard ranking for a user on a project, based on task completion, over
134
+ * the given number of months (or start and end dates). Included with the user is their top challenges
135
+ * (by amount of activity). Also a bracketing number of users above and below
136
+ * the user in the rankings.
137
+ *
138
+ * @param userId user Id for user
139
+ * @param bracket the number of users to return above and below the given user (0 returns just the user)
140
+ * @return User with score and ranking based on task completion activity
141
+ */
142
+ def getProjectLeaderboardForUser (
143
+ userId : Int ,
144
+ projectId : Int ,
145
+ monthDuration : Int ,
146
+ bracket : Int
147
+ ): Action [AnyContent ] = Action .async { implicit request =>
148
+ this .sessionManager.userAwareRequest { implicit user =>
149
+ SearchParameters .withSearch { implicit params =>
150
+ Ok (
151
+ Json .toJson(
152
+ this .service.getChallengeLeaderboardForUser(
153
+ userId,
154
+ projectId,
155
+ monthDuration,
156
+ bracket
157
+ )
158
+ )
159
+ )
160
+ }
161
+ }
162
+ }
163
+
55
164
/**
56
165
* Gets the leaderboard ranking for a user, based on task completion, over
57
166
* the given number of months (or start and end dates). Included with the user is their top challenges
0 commit comments