Merge branch 'api-filter-user-tournaments-by-status' of git://github.com/nnickoloff1234/lila into nnickoloff1234-api-filter-user-tournaments-by-status

* 'api-filter-user-tournaments-by-status' of git://github.com/nnickoloff1234/lila:
  Update TournamentRepo.scala
  add status filter parameter to users created tournaments api
pull/9850/head
Thibault Duplessis 2021-09-20 18:38:32 +02:00
commit ab0c01e2a1
4 changed files with 7 additions and 6 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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)