add /api/team/:id/arena endpoints - for #6759

pull/6909/head
Thibault Duplessis 2020-07-01 10:16:46 +02:00
parent 2a0094278b
commit de4a4c8033
4 changed files with 31 additions and 10 deletions

View File

@ -17,7 +17,10 @@ import views._
final class Tournament(
env: Env,
teamC: => Team
teamC: => Team,
apiC: => Api
)(implicit
mat: akka.stream.Materializer
) extends LilaController(env) {
private def repo = env.tournament.tournamentRepo
@ -451,6 +454,18 @@ final class Tournament(
}
}
def byTeam(id: String) =
Action.async { implicit req =>
implicit val lang = reqLang
apiC.jsonStream {
env.tournament.tournamentRepo
.byTeamCursor(id)
.documentSource(getInt("max", req) | 100)
.mapAsync(1)(env.tournament.apiJsonView.fullJson)
.throttle(20, 1.second)
}.fuccess
}
private def WithEditableTournament(id: String, me: UserModel)(
f: Tour => Fu[Result]
)(implicit ctx: Context): Fu[Result] =

View File

@ -310,6 +310,7 @@ GET /api/team/search controllers.Team.apiSearch(text: S
GET /api/team/of/:username controllers.Team.apiTeamsOf(username: String)
GET /api/team/:id controllers.Team.apiShow(id: String)
GET /api/team/:id/users controllers.Team.users(id: String)
GET /api/team/:id/arena controllers.Tournament.byTeam(id: String)
# Analyse
POST /$gameId<\w{8}>/request-analysis controllers.Analyse.requestAnalysis(gameId: String)

View File

@ -50,22 +50,21 @@ final class ApiJsonView(lightUserApi: LightUserApi)(implicit ec: scala.concurren
"short" -> tour.variant.shortName,
"name" -> tour.variant.name
),
"secondsToStart" -> tour.secondsToStart,
"startsAt" -> tour.startsAt,
"finishesAt" -> tour.finishesAt,
"status" -> tour.status.id,
"perf" -> tour.perfType.map(perfJson)
"startsAt" -> tour.startsAt,
"finishesAt" -> tour.finishesAt,
"status" -> tour.status.id,
"perf" -> tour.perfType.map(perfJson)
)
.add("secondsToStart", tour.secondsToStart.some.filter(0 <))
.add("hasMaxRating", tour.conditions.maxRating.isDefined)
.add("private", tour.isPrivate)
.add("position", tour.position.some.filterNot(_.initial) map positionJson)
.add("schedule", tour.schedule map scheduleJson)
def fullJson(tour: Tournament)(implicit lang: Lang): Fu[JsObject] =
for {
owner <- tour.nonLichessCreatedBy ?? lightUserApi.async
winner <- tour.winnerId ?? lightUserApi.async
} yield baseJson(tour) ++ Json.obj("winner" -> winner.map(userJson))
(tour.winnerId ?? lightUserApi.async) map { winner =>
baseJson(tour).add("winner" -> winner.map(userJson))
}
private def userJson(u: lila.common.LightUser) =
Json.obj(

View File

@ -105,6 +105,12 @@ final class TournamentRepo(val coll: Coll, playerCollName: CollName)(implicit
def clockById(id: Tournament.ID): Fu[Option[chess.Clock.Config]] =
coll.primitiveOne[chess.Clock.Config]($id(id), "clock")
def byTeamCursor(teamId: TeamID) =
coll.ext
.find(forTeamSelect(teamId))
.sort($sort desc "startsAt")
.cursor[Tournament]()
private[tournament] def upcomingByTeam(teamId: TeamID, nb: Int) =
(nb > 0) ?? coll.ext
.find(