diff --git a/app/controllers/Api.scala b/app/controllers/Api.scala index 9b52fa8743..3adde9b5f8 100644 --- a/app/controllers/Api.scala +++ b/app/controllers/Api.scala @@ -269,7 +269,7 @@ final class Api( } } - def tournamentsByOwner(name: String) = + def tournamentsByOwner(name: String, status: List[Int]) = Action.async { implicit req => implicit val lang = reqLang (name != "lichess") ?? env.user.repo.named(name) flatMap { @@ -277,7 +277,7 @@ final class Api( val nb = getInt("nb", req) | Int.MaxValue jsonStream { env.tournament.api - .byOwnerStream(user, MaxPerSecond(20), nb) + .byOwnerStream(user, status, MaxPerSecond(20), nb) .mapAsync(1)(env.tournament.apiJsonView.fullJson) }.fuccess } diff --git a/conf/routes b/conf/routes index 9af35d4d32..d79d2bc66f 100644 --- a/conf/routes +++ b/conf/routes @@ -640,7 +640,7 @@ GET /api/user/puzzle-activity controllers.Puzzle.activity GET /api/puzzle/daily controllers.Puzzle.apiDaily GET /api/puzzle/activity controllers.Puzzle.activity GET /api/puzzle/dashboard/:days controllers.Puzzle.apiDashboard(days: Int) -GET /api/user/:name/tournament/created controllers.Api.tournamentsByOwner(name: String) +GET /api/user/:name/tournament/created controllers.Api.tournamentsByOwner(name: String, status: List[Int]) GET /api/user/:name controllers.Api.user(name: String) GET /api/user/:name/activity controllers.Api.activity(name: String) POST /api/user/:name/note controllers.User.apiWriteNote(name: String) diff --git a/modules/tournament/src/main/TournamentApi.scala b/modules/tournament/src/main/TournamentApi.scala index 09567c4b37..eab0bb2d8d 100644 --- a/modules/tournament/src/main/TournamentApi.scala +++ b/modules/tournament/src/main/TournamentApi.scala @@ -668,9 +668,9 @@ final class TournamentApi( } } - def byOwnerStream(owner: User, perSecond: MaxPerSecond, nb: Int): Source[Tournament, _] = + def byOwnerStream(owner: User, status: List[Int], perSecond: MaxPerSecond, nb: Int): Source[Tournament, _] = tournamentRepo - .sortedCursor(owner, perSecond.value) + .sortedCursor(owner, status, perSecond.value) .documentSource(nb) .throttle(perSecond.value, 1 second) diff --git a/modules/tournament/src/main/TournamentRepo.scala b/modules/tournament/src/main/TournamentRepo.scala index 1ff2ef68e6..35f713de8c 100644 --- a/modules/tournament/src/main/TournamentRepo.scala +++ b/modules/tournament/src/main/TournamentRepo.scala @@ -389,11 +389,12 @@ final class TournamentRepo(val coll: Coll, playerCollName: CollName)(implicit private[tournament] def sortedCursor( owner: lila.user.User, + status: List[Int], batchSize: Int, readPreference: ReadPreference = ReadPreference.secondaryPreferred ): AkkaStreamCursor[Tournament] = coll - .find($doc("createdBy" -> owner.id)) + .find($doc("createdBy" -> owner.id ) ++ ( !status.isEmpty ?? $doc("status" $in status) )) .sort($sort desc "startsAt") .batchSize(batchSize) .cursor[Tournament](readPreference)