forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTournamentCrud.scala
66 lines (56 loc) · 1.83 KB
/
TournamentCrud.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package controllers
import lila.app._
import views._
final class TournamentCrud(env: Env) extends LilaController(env) {
private def crud = env.tournament.crudApi
def index(page: Int) =
Secure(_.ManageTournament) { implicit ctx => _ =>
crud.paginator(page) map { paginator =>
html.tournament.crud.index(paginator)
}
}
def edit(id: String) =
Secure(_.ManageTournament) { implicit ctx => _ =>
OptionOk(crud one id) { tour =>
html.tournament.crud.edit(tour, crud editForm tour)
}
}
def update(id: String) =
SecureBody(_.ManageTournament) { implicit ctx => _ =>
OptionFuResult(crud one id) { tour =>
implicit val req = ctx.body
crud
.editForm(tour)
.bindFromRequest
.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
crud.createForm.bindFromRequest.fold(
err => BadRequest(html.tournament.crud.create(err)).fuccess,
data =>
crud.create(data, me) map { tour =>
Redirect {
if (tour.isTeamBattle) routes.Tournament.teamBattleEdit(tour.id)
else routes.TournamentCrud.edit(tour.id)
}.flashSuccess
}
)
}
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
}
}
}