2016-06-23 01:45:11 -06:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import lila.app._
|
|
|
|
|
2016-06-29 12:24:28 -06:00
|
|
|
import play.api.data._
|
|
|
|
import play.api.data.Forms._
|
2016-06-23 01:45:11 -06:00
|
|
|
import play.api.libs.json._
|
|
|
|
import views.html
|
|
|
|
|
2019-12-04 16:39:16 -07:00
|
|
|
final class Learn(env: Env) extends LilaController(env) {
|
2016-06-23 01:45:11 -06:00
|
|
|
|
|
|
|
import lila.learn.JSONHandlers._
|
|
|
|
|
2020-05-05 22:11:15 -06:00
|
|
|
def index =
|
|
|
|
Open { implicit ctx =>
|
|
|
|
pageHit
|
|
|
|
ctx.me
|
|
|
|
.?? { me =>
|
|
|
|
env.learn.api.get(me) map { Json.toJson(_) } map some
|
|
|
|
}
|
|
|
|
.map { progress =>
|
|
|
|
Ok(html.learn.index(progress))
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 12:24:28 -06:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
private val scoreForm = Form(
|
|
|
|
mapping(
|
|
|
|
"stage" -> nonEmptyText,
|
|
|
|
"level" -> number,
|
|
|
|
"score" -> number
|
|
|
|
)(Tuple3.apply)(Tuple3.unapply)
|
|
|
|
)
|
2016-06-29 12:24:28 -06:00
|
|
|
|
2020-05-05 22:11:15 -06:00
|
|
|
def score =
|
|
|
|
AuthBody { implicit ctx => me =>
|
|
|
|
implicit val body = ctx.body
|
2020-07-22 04:52:52 -06:00
|
|
|
scoreForm
|
|
|
|
.bindFromRequest()
|
|
|
|
.fold(
|
|
|
|
_ => BadRequest.fuccess,
|
2020-09-21 01:28:28 -06:00
|
|
|
{ case (stage, level, s) =>
|
|
|
|
val score = lila.learn.StageProgress.Score(s)
|
|
|
|
env.learn.api.setScore(me, stage, level, score) >>
|
|
|
|
env.activity.write.learn(me.id, stage) inject Ok(Json.obj("ok" -> true))
|
2020-07-22 04:52:52 -06:00
|
|
|
}
|
|
|
|
)
|
2020-05-05 22:11:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def reset =
|
|
|
|
AuthBody { _ => me =>
|
|
|
|
env.learn.api.reset(me) inject Ok(Json.obj("ok" -> true))
|
|
|
|
}
|
2016-06-23 01:45:11 -06:00
|
|
|
}
|