Skip to content

Commit

Permalink
replace official field with tier in broadcast apis
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 12, 2024
1 parent 9deb20b commit bf7f38e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/relay/src/main/JsonView.scala
Expand Up @@ -14,6 +14,9 @@ final class JsonView(baseUrl: BaseUrl, markup: RelayMarkup, leaderboardApi: Rela
import JsonView.given
import lila.study.JsonView.given

given Writes[Option[RelayTour.Tier]] = Writes: t =>
JsString(t.flatMap(RelayTour.Tier.keys.get) | "user")

given OWrites[RelayTour] = OWrites: t =>
Json
.obj(
Expand All @@ -23,7 +26,7 @@ final class JsonView(baseUrl: BaseUrl, markup: RelayMarkup, leaderboardApi: Rela
"description" -> t.description,
"createdAt" -> t.createdAt
)
.add("official" -> t.official)
.add("tier" -> t.tier)

given OWrites[RelayRound] = OWrites: r =>
Json
Expand Down
1 change: 1 addition & 0 deletions modules/relay/src/main/RelayTour.scala
Expand Up @@ -55,6 +55,7 @@ object RelayTour:
def name(tier: Tier) = options.collectFirst {
case (t, n) if t == tier.toString => n
} | "???"
val keys: Map[Tier, String] = Map(NORMAL -> "normal", HIGH -> "high", BEST -> "best")

case class Spotlight(enabled: Boolean, language: Language, title: Option[String]):
def isEmpty = !enabled && specialLanguage.isEmpty && title.isEmpty
Expand Down

1 comment on commit bf7f38e

@tors42
Copy link
Contributor

@tors42 tors42 commented on bf7f38e Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the expectation was that tier should be rendered as a string in the API (documentation example show "tier":"high"),
but when I try it shows up as a number:

curl -H "authorization: Bearer lip_admin" -H "accept: application/x-ndjson" http://localhost:8080/api/broadcast/my-rounds | jq

{
  "round": {
    "id": "wrgYAgcW",
    "name": "Round 1",
    "slug": "round-1",
    "createdAt": 1705074079821,
    "url": "http://localhost:8080/broadcast/hightierbroadcast/round-1/wrgYAgcW"
  },
  "tour": {
    "id": "gr9V5JRd",
    "name": "HighTierBroadcast",
    "slug": "hightierbroadcast",
    "description": "Testing API update",
    "createdAt": 1705074074004,
    "tier": 4
  },
  "study": {
    "writeable": true
  }
}

Test system is lila-docker in which I logged in with Admin account with web browser and created a new broadcast + round.

Please sign in to comment.