expose puzzle dashboard through oAuth API
parent
458ef12aef
commit
1313b91e72
|
@ -262,10 +262,11 @@ final class Puzzle(
|
|||
.fuccess
|
||||
}
|
||||
|
||||
def dashboard(days: Int) =
|
||||
Scoped(_.Puzzle.Read) { _ => me =>
|
||||
JsonOk {
|
||||
env.puzzle.dashboard(me, days) map env.puzzle.json.dashboardJson map
|
||||
def apiDashboard(days: Int) =
|
||||
Scoped(_.Puzzle.Read) { implicit req => me =>
|
||||
implicit val lang = reqLang
|
||||
JsonOptionOk {
|
||||
env.puzzle.dashboard(me, days) map2 { env.puzzle.jsonView.dashboardJson(_, days) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -565,7 +565,7 @@ GET /api controllers.Api.index
|
|||
POST /api/users controllers.Api.usersByIds
|
||||
GET /api/user/puzzle-activity controllers.Puzzle.activity
|
||||
GET /api/puzzle/activity controllers.Puzzle.activity
|
||||
GET /api/puzzle/dashboard controllers.Puzzle.dashboard
|
||||
GET /api/puzzle/dashboard/:days controllers.Puzzle.apiDashboard(days: Int)
|
||||
GET /api/user/:name/tournament/created controllers.Api.tournamentsByOwner(name: String)
|
||||
GET /api/user/:name controllers.Api.user(name: String)
|
||||
GET /api/user/:name/activity controllers.Api.activity(name: String)
|
||||
|
|
|
@ -82,6 +82,25 @@ final class JsonView(
|
|||
"is3d" -> p.is3d
|
||||
)
|
||||
|
||||
def dashboardJson(dash: PuzzleDashboard, days: Int)(implicit lang: Lang) = Json.obj(
|
||||
"days" -> days,
|
||||
"global" -> dashboardResults(dash.global),
|
||||
"themes" -> JsObject(dash.byTheme.toList.sortBy(-_._2.nb).map { case (key, res) =>
|
||||
key.value -> Json.obj(
|
||||
"theme" -> PuzzleTheme(key).name.txt(),
|
||||
"results" -> dashboardResults(res)
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
private def dashboardResults(res: PuzzleDashboard.Results) = Json.obj(
|
||||
"nb" -> res.nb,
|
||||
"firstWins" -> res.wins,
|
||||
"replayWins" -> res.fixed,
|
||||
"puzzleRatingAvg" -> res.puzzleRatingAvg,
|
||||
"performance" -> res.performance
|
||||
)
|
||||
|
||||
private def puzzleJson(puzzle: Puzzle): JsObject = Json.obj(
|
||||
"id" -> puzzle.id,
|
||||
"rating" -> puzzle.glicko.intRating,
|
||||
|
|
Loading…
Reference in New Issue