lila/app/controllers/Event.scala

63 lines
1.6 KiB
Scala
Raw Normal View History

2016-08-22 16:05:10 -06:00
package controllers
import lila.app._
import views._
2019-12-04 16:39:16 -07:00
final class Event(env: Env) extends LilaController(env) {
2016-08-22 16:05:10 -06:00
2019-12-04 16:39:16 -07:00
private def api = env.event.api
2016-08-22 16:05:10 -06:00
2016-08-24 15:43:35 -06:00
def show(id: String) = Open { implicit ctx =>
OptionOk(api oneEnabled id) { event =>
html.event.show(event)
}
}
2019-12-08 10:35:26 -07:00
def manager = Secure(_.ManageEvent) { implicit ctx => _ =>
api.list map { events =>
html.event.manager(events)
}
2016-08-22 16:05:10 -06:00
}
2019-12-08 10:35:26 -07:00
def edit(id: String) = Secure(_.ManageEvent) { implicit ctx => _ =>
OptionOk(api one id) { event =>
html.event.edit(event, api editForm event)
}
2016-08-22 16:05:10 -06:00
}
2019-12-08 10:35:26 -07:00
def update(id: String) = SecureBody(_.ManageEvent) { implicit ctx => _ =>
OptionFuResult(api one id) { event =>
implicit val req = ctx.body
2019-12-13 07:30:20 -07:00
api
.editForm(event)
.bindFromRequest
.fold(
err => BadRequest(html.event.edit(event, err)).fuccess,
data => api.update(event, data) inject Redirect(routes.Event.edit(id))
)
}
2016-08-22 16:05:10 -06:00
}
2019-12-08 10:35:26 -07:00
def form = Secure(_.ManageEvent) { implicit ctx => _ =>
Ok(html.event.create(api.createForm)).fuccess
2016-08-22 16:05:10 -06:00
}
def create = SecureBody(_.ManageEvent) { implicit ctx => me =>
implicit val req = ctx.body
api.createForm.bindFromRequest.fold(
err => BadRequest(html.event.create(err)).fuccess,
2019-12-13 07:30:20 -07:00
data =>
api.create(data, me.id) map { event =>
Redirect(routes.Event.edit(event.id))
}
)
2016-08-22 16:05:10 -06:00
}
2019-09-04 07:23:48 -06:00
2019-12-08 10:35:26 -07:00
def cloneE(id: String) = Secure(_.ManageEvent) { implicit ctx => _ =>
2019-09-04 07:23:48 -06:00
OptionFuResult(api one id) { old =>
val event = api clone old
Ok(html.event.create(api editForm event)).fuccess
}
}
2016-08-22 16:05:10 -06:00
}