/api/games/user sort query parameter
parent
8c3d7757a7
commit
1709f2e214
|
@ -90,6 +90,7 @@ final class Game(
|
|||
color = get("color", req) flatMap chess.Color.fromName,
|
||||
analysed = getBoolOpt("analysed", req),
|
||||
flags = requestPgnFlags(req, extended = false).copy(literate = false),
|
||||
sort = if (get("sort", req) has "dateAsc") GameApiV2.DateAsc else GameApiV2.DateDesc,
|
||||
perSecond = MaxPerSecond(me match {
|
||||
case Some(m) if m is user.id => 60
|
||||
case Some(_) if oauth => 30 // bonus for oauth logged in only (not for CSRF)
|
||||
|
|
|
@ -114,7 +114,7 @@ final class GameApiV2(
|
|||
.sortedCursor(
|
||||
config.vs.fold(Query.user(config.user.id)) { Query.opponents(config.user, _) } ++
|
||||
Query.createdBetween(config.since, config.until) ++ Query.finished,
|
||||
Query.sortCreated,
|
||||
config.sort.bson,
|
||||
batchSize = config.perSecond.value
|
||||
)
|
||||
.documentSource()
|
||||
|
@ -339,6 +339,10 @@ object GameApiV2 {
|
|||
val flags: WithFlags
|
||||
}
|
||||
|
||||
sealed abstract class GameSort(val bson: Bdoc)
|
||||
case object DateAsc extends GameSort(Query.sortChronological)
|
||||
case object DateDesc extends GameSort(Query.sortAntiChronological)
|
||||
|
||||
case class OneConfig(
|
||||
format: Format,
|
||||
imported: Boolean,
|
||||
|
@ -358,6 +362,7 @@ object GameApiV2 {
|
|||
analysed: Option[Boolean] = None,
|
||||
color: Option[chess.Color],
|
||||
flags: WithFlags,
|
||||
sort: GameSort,
|
||||
perSecond: MaxPerSecond,
|
||||
playerFile: Option[String]
|
||||
) extends Config {
|
||||
|
|
Loading…
Reference in New Issue