Merge pull request #4018 from RankWeis/master
Adding game completion percentage to user API
This commit is contained in:
commit
8d4bbb2b05
|
@ -19,6 +19,7 @@ final class Env(
|
|||
getTourAndRanks: lila.game.Game => Fu[Option[lila.tournament.TourAndRanks]],
|
||||
crosstableApi: lila.game.CrosstableApi,
|
||||
prefApi: lila.pref.PrefApi,
|
||||
playBanApi: lila.playban.PlaybanApi,
|
||||
gamePgnDump: lila.game.PgnDump,
|
||||
gameCache: lila.game.Cached,
|
||||
userEnv: lila.user.Env,
|
||||
|
@ -84,6 +85,7 @@ final class Env(
|
|||
relationApi = relationApi,
|
||||
bookmarkApi = bookmarkApi,
|
||||
crosstableApi = crosstableApi,
|
||||
playBanApi = playBanApi,
|
||||
gameCache = gameCache,
|
||||
prefApi = prefApi
|
||||
)
|
||||
|
@ -155,6 +157,7 @@ object Env {
|
|||
bookmarkApi = lila.bookmark.Env.current.api,
|
||||
getTourAndRanks = lila.tournament.Env.current.tourAndRanks,
|
||||
crosstableApi = lila.game.Env.current.crosstableApi,
|
||||
playBanApi = lila.playban.Env.current.api,
|
||||
prefApi = lila.pref.Env.current.api,
|
||||
gamePgnDump = lila.game.Env.current.pgnDump,
|
||||
gameCache = lila.game.Env.current.cached,
|
||||
|
|
|
@ -11,6 +11,7 @@ private[api] final class UserApi(
|
|||
relationApi: lila.relation.RelationApi,
|
||||
bookmarkApi: lila.bookmark.BookmarkApi,
|
||||
crosstableApi: lila.game.CrosstableApi,
|
||||
playBanApi: lila.playban.PlaybanApi,
|
||||
gameCache: lila.game.Cached,
|
||||
prefApi: lila.pref.PrefApi,
|
||||
makeUrl: String => String
|
||||
|
@ -39,14 +40,18 @@ private[api] final class UserApi(
|
|||
ctx.userId.?? { relationApi.fetchFollows(u.id, _) } zip
|
||||
bookmarkApi.countByUser(u) zip
|
||||
gameCache.nbPlaying(u.id) zip
|
||||
gameCache.nbImportedBy(u.id) map {
|
||||
case gameOption ~ nbGamesWithMe ~ following ~ followers ~ followable ~ relation ~ isFollowed ~ nbBookmarks ~ nbPlaying ~ nbImported =>
|
||||
gameCache.nbImportedBy(u.id) zip
|
||||
playBanApi.completionRate(u.id).map(_.map { cr => math.round(cr * 100) }.getOrElse(0L)) map
|
||||
{
|
||||
case gameOption ~ nbGamesWithMe ~ following ~ followers ~ followable ~ relation ~
|
||||
isFollowed ~ nbBookmarks ~ nbPlaying ~ nbImported ~ completionRate =>
|
||||
jsonView(u) ++ {
|
||||
Json.obj(
|
||||
"url" -> makeUrl(s"@/$username"),
|
||||
"playing" -> gameOption.map(g => makeUrl(s"${g.gameId}/${g.color.name}")),
|
||||
"nbFollowing" -> following,
|
||||
"nbFollowers" -> followers,
|
||||
"completionRate" -> completionRate,
|
||||
"count" -> Json.obj(
|
||||
"all" -> u.count.game,
|
||||
"rated" -> u.count.rated,
|
||||
|
|
Loading…
Reference in a new issue