add an API endpoint to update tournament informations - closes #8128

pull/8134/head
Thibault Duplessis 2021-02-09 16:50:45 +01:00
parent 3aad2b7476
commit 0a52593240
4 changed files with 34 additions and 3 deletions

View File

@ -355,6 +355,36 @@ final class Tournament(
)
}
def apiUpdate(id: String) =
ScopedBody(_.Tournament.Write) { implicit req => me =>
implicit def lang = reqLang
repo byId id flatMap {
_.filter(_.createdBy == me.id || isGranted(_.ManageTournament, me)) ?? { tour =>
env.team.api.lightsByLeader(me.id) flatMap { teams =>
forms
.edit(me, teams, tour)
.bindFromRequest()
.fold(
newJsonFormError,
data =>
api.update(tour, data, teams) flatMap { tour =>
jsonView(
tour,
none,
none,
getUserTeamIds = _ => fuccess(teams.map(_.id)),
env.team.getTeamName,
none,
none,
partial = false
)(reqLang) map { Ok(_) }
}
)
}
}
}
}
def teamBattleEdit(id: String) =
Auth { implicit ctx => me =>
repo byId id flatMap {

View File

@ -594,6 +594,7 @@ GET /api/tournament/:id/games controllers.Api.tournamentGames(id: Strin
GET /api/tournament/:id/results controllers.Api.tournamentResults(id: String)
GET /api/tournament/:id/teams controllers.Api.tournamentTeams(id: String)
POST /api/tournament controllers.Tournament.apiCreate
POST /api/tournament/:id controllers.Tournament.apiUpdate(id: String)
POST /api/tournament/team-battle/:id controllers.Tournament.apiTeamBattleUpdate(id: String)
POST /api/swiss/new/:teamId controllers.Swiss.apiCreate(teamId: String)
GET /api/swiss/:id/games controllers.Api.swissGames(id: String)

View File

@ -27,7 +27,7 @@ object OAuthScope {
}
object Tournament {
case object Write extends OAuthScope("tournament:write", "Create tournaments")
case object Write extends OAuthScope("tournament:write", "Create and update tournaments")
}
object Puzzle {

View File

@ -99,7 +99,7 @@ final class TournamentApi(
} inject tour
}
def update(old: Tournament, data: TournamentSetup, leaderTeams: List[LeaderTeam]): Funit = {
def update(old: Tournament, data: TournamentSetup, leaderTeams: List[LeaderTeam]): Fu[Tournament] = {
import data._
val variant = if (old.isCreated) realVariant else old.variant
val tour = old
@ -127,7 +127,7 @@ final class TournamentApi(
.copy(teamMember = old.conditions.teamMember) // can't change that
)
}
tournamentRepo update tour void
tournamentRepo update tour inject tour
}
def teamBattleUpdate(