Skip to content

Commit

Permalink
Add dashboard endpoint for mobile.
Browse files Browse the repository at this point in the history
Instead of having one endpoint for strenght/weakness, every theme stats is included and they can be sorted out by the app itself.

For now endpoint name is temporary.

Example:
`GET   /training/mobile/dashboard/6`

```json
{
  "days": 6,
  "global": {
    "nb": 12,
    "firstWins": 9,
    "replayWins": 2,
    "puzzleRatingAvg": 1292,
    "performance": 1375
  },
  "themes": {
    "xRayAttack": {
      "theme": "X-Ray attack",
      "results": {
        "nb": 6,
        "firstWins": 5,
        "replayWins": 2,
        "puzzleRatingAvg": 1239,
        "performance": 1239
      }
    },
    "mix": {
      "theme": "Healthy mix",
      "results": {
        "nb": 5,
        "firstWins": 3,
        "replayWins": 0,
        "puzzleRatingAvg": 1495,
        "performance": 1595
      }
    },
    "middlegame": {
      "theme": "Middlegame",
      "results": {
        "nb": 4,
        "firstWins": 4,
        "replayWins": 1,
        "puzzleRatingAvg": 1197,
        "performance": 1447
      }
    }
  ...
}
```
  • Loading branch information
kraktus committed Nov 13, 2021
1 parent fc81966 commit e706ee6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/controllers/Puzzle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,23 @@ final class Puzzle(
.fuccess
}

def mobileDashboard(days: Int) =
Auth { implicit ctx => me =>
negotiate(
html = notFound,
_ => renderMobileAndApiJson(days, me)
)
}

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) }
}
renderMobileAndApiJson(days, me)
}

private def renderMobileAndApiJson(days: Int, me: lila.user.User)(implicit lang: play.api.i18n.Lang) =
JsonOptionOk {
env.puzzle.dashboard(me, days) map2 { env.puzzle.jsonView.dashboardJson(_, days) }
}

def dashboard(days: Int, path: String = "home") =
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ GET /training/frame controllers.Puzzle.frame
GET /training/export/gif/thumbnail/:id.gif controllers.Export.puzzleThumbnail(id: String)
GET /training/themes controllers.Puzzle.themes
GET /training/of-player controllers.Puzzle.ofPlayer(name: Option[String] ?= None, page: Int ?= 1)
GET /training/mobile/dashboard/$days<\d+> controllers.Puzzle.mobileDashboard(days: Int)
GET /training/dashboard/$days<\d+> controllers.Puzzle.dashboard(days: Int, path: String = "home")
GET /training/dashboard/$days<\d+>/:path controllers.Puzzle.dashboard(days: Int, path: String)
GET /training/replay/$days<\d+>/:theme controllers.Puzzle.replay(days: Int, theme: String)
Expand Down

0 comments on commit e706ee6

Please sign in to comment.