api to create swiss tournaments
parent
078fc72695
commit
8309a9d6b5
|
@ -95,6 +95,28 @@ final class Swiss(
|
|||
}
|
||||
}
|
||||
|
||||
def apiCreate(teamId: String) =
|
||||
ScopedBody() { implicit req => me =>
|
||||
if (me.isBot || me.lame) notFoundJson("This account cannot create tournaments")
|
||||
else
|
||||
env.team.teamRepo.isLeader(teamId, me.id) flatMap {
|
||||
case false => notFoundJson("You're not a leader of that team")
|
||||
case _ =>
|
||||
env.swiss.forms.create.bindFromRequest
|
||||
.fold(
|
||||
jsonFormErrorDefaultLang,
|
||||
data =>
|
||||
tourC.rateLimitCreation(me, false, req) {
|
||||
JsonOk {
|
||||
env.swiss.api.create(data, me, teamId) flatMap { swiss =>
|
||||
env.swiss.json(swiss, me.some, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def join(id: String) =
|
||||
AuthBody { implicit ctx => me =>
|
||||
NoLameOrBot {
|
||||
|
|
|
@ -554,6 +554,7 @@ GET /api/tournament/:id controllers.Api.tournament(id: String)
|
|||
GET /api/tournament/:id/games controllers.Api.tournamentGames(id: String)
|
||||
GET /api/tournament/:id/results controllers.Api.tournamentResults(id: String)
|
||||
POST /api/tournament controllers.Tournament.apiCreate
|
||||
POST /api/swiss/new/:teamId controllers.Swiss.apiCreate(teamId: String)
|
||||
GET /api/simul controllers.Simul.apiList
|
||||
GET /api/status controllers.Api.status
|
||||
GET /api/users/status controllers.Api.usersStatus
|
||||
|
|
|
@ -28,11 +28,11 @@ final class SwissForm {
|
|||
),
|
||||
"clock" -> mapping(
|
||||
"limit" -> number.verifying(clockLimits.contains _),
|
||||
"increment" -> number(min = 0, max = 180)
|
||||
"increment" -> number(min = 0, max = 600)
|
||||
)(ClockConfig.apply)(ClockConfig.unapply)
|
||||
.verifying("Invalid clock", _.estimateTotalSeconds > 0),
|
||||
"startsAt" -> optional(inTheFuture(ISODateTimeOrTimestamp.isoDateTimeOrTimestamp)),
|
||||
"variant" -> nonEmptyText.verifying(v => Variant(v).isDefined),
|
||||
"variant" -> optional(nonEmptyText.verifying(v => Variant(v).isDefined)),
|
||||
"rated" -> boolean,
|
||||
"nbRounds" -> number(min = 3, max = 100),
|
||||
"description" -> optional(nonEmptyText),
|
||||
|
@ -46,9 +46,9 @@ final class SwissForm {
|
|||
name = none,
|
||||
clock = ClockConfig(180, 0),
|
||||
startsAt = Some(DateTime.now plusMinutes 10),
|
||||
variant = Variant.default.key,
|
||||
variant = Variant.default.key.some,
|
||||
rated = true,
|
||||
nbRounds = 10,
|
||||
nbRounds = 8,
|
||||
description = none,
|
||||
hasChat = true.some,
|
||||
roundInterval = 60.some
|
||||
|
@ -59,7 +59,7 @@ final class SwissForm {
|
|||
name = s.name.some,
|
||||
clock = s.clock,
|
||||
startsAt = s.startsAt.some,
|
||||
variant = s.variant.key,
|
||||
variant = s.variant.key.some,
|
||||
rated = s.settings.rated,
|
||||
nbRounds = s.settings.nbRounds,
|
||||
description = s.settings.description,
|
||||
|
@ -91,14 +91,14 @@ object SwissForm {
|
|||
name: Option[String],
|
||||
clock: ClockConfig,
|
||||
startsAt: Option[DateTime],
|
||||
variant: String,
|
||||
variant: Option[String],
|
||||
rated: Boolean,
|
||||
nbRounds: Int,
|
||||
description: Option[String],
|
||||
hasChat: Option[Boolean],
|
||||
roundInterval: Option[Int]
|
||||
) {
|
||||
def realVariant = Variant orDefault variant
|
||||
def realVariant = variant flatMap Variant.apply getOrElse Variant.default
|
||||
def realStartsAt = startsAt | DateTime.now.plusMinutes(10)
|
||||
def realRoundInterval = (roundInterval | 60).seconds
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ final class SwissJson(
|
|||
def apply(
|
||||
swiss: Swiss,
|
||||
me: Option[User],
|
||||
reqPage: Option[Int], // None = focus on me
|
||||
socketVersion: Option[SocketVersion],
|
||||
isInTeam: Boolean,
|
||||
playerInfo: Option[SwissPlayer.ViewExt]
|
||||
reqPage: Option[Int] = None, // None = focus on me
|
||||
socketVersion: Option[SocketVersion] = None,
|
||||
playerInfo: Option[SwissPlayer.ViewExt] = None
|
||||
): Fu[JsObject] = {
|
||||
for {
|
||||
myInfo <- me.?? { fetchMyInfo(swiss, _) }
|
||||
|
|
Loading…
Reference in New Issue