lila/app/controllers/TournamentCrud.scala

69 lines
1.9 KiB
Scala
Raw Normal View History

2016-03-28 05:08:48 -06:00
package controllers
import lila.app._
import views._
2019-12-04 16:39:16 -07:00
final class TournamentCrud(env: Env) extends LilaController(env) {
2016-03-28 05:08:48 -06:00
2019-12-04 16:39:16 -07:00
private def crud = env.tournament.crudApi
2016-03-28 05:08:48 -06:00
2020-05-05 22:11:15 -06:00
def index(page: Int) =
Secure(_.ManageTournament) { implicit ctx => _ =>
crud.paginator(page) map { paginator =>
html.tournament.crud.index(paginator)
}
}
2016-03-28 05:08:48 -06:00
2020-05-05 22:11:15 -06:00
def edit(id: String) =
Secure(_.ManageTournament) { implicit ctx => _ =>
OptionOk(crud one id) { tour =>
html.tournament.crud.edit(tour, crud editForm tour)
}
}
2016-03-28 05:08:48 -06:00
2020-05-05 22:11:15 -06:00
def update(id: String) =
SecureBody(_.ManageTournament) { implicit ctx => _ =>
OptionFuResult(crud one id) { tour =>
implicit val req = ctx.body
crud
.editForm(tour)
2020-07-07 02:34:48 -06:00
.bindFromRequest()
2020-05-05 22:11:15 -06:00
.fold(
err => BadRequest(html.tournament.crud.edit(tour, err)).fuccess,
data => crud.update(tour, data) inject Redirect(routes.TournamentCrud.edit(id)).flashSuccess
)
}
}
def form =
Secure(_.ManageTournament) { implicit ctx => _ =>
Ok(html.tournament.crud.create(crud.createForm)).fuccess
}
def create =
SecureBody(_.ManageTournament) { implicit ctx => me =>
implicit val req = ctx.body
2020-07-22 04:52:52 -06:00
crud.createForm
.bindFromRequest()
.fold(
err => BadRequest(html.tournament.crud.create(err)).fuccess,
data =>
crud.create(data, me.user) map { tour =>
2020-07-22 04:52:52 -06:00
Redirect {
if (tour.isTeamBattle) routes.Tournament.teamBattleEdit(tour.id)
else routes.TournamentCrud.edit(tour.id)
}.flashSuccess
}
)
}
2020-05-05 22:11:15 -06:00
def cloneT(id: String) =
Secure(_.ManageTournament) { implicit ctx => _ =>
OptionFuResult(crud one id) { old =>
val tour = crud clone old
Ok(html.tournament.crud.create(crud editForm tour)).fuccess
}
2019-08-21 11:32:50 -06:00
}
2016-03-28 05:08:48 -06:00
}