speedruncomorg / api

REST API Documentation for speedrun.com
347 stars 35 forks source link

Embed Moderator Status when embedding Users into Game #17

Open CryZe opened 9 years ago

CryZe commented 9 years ago

When embedding users into a game, you completely lose the information about what kind of moderator they are. This is not that important of an issue, as you could just query the game again or something, but it's still weird that embedding is actually worse in that case.

I explicitly need to state that this information might not exist in the object for example: https://github.com/LiveSplit/SpeedrunComSharp/blob/master/SpeedrunComSharp/Game.cs#L32

sgt-kabukiman commented 9 years ago

Yes, I already noticed that this is kind of bad. Need to take another look at it.

sgt-kabukiman commented 9 years ago

The underlying library we use to construct the JSON does not really give us much flexibility here. Even when changing the structure to something like

{
  "moderators": [
    {"user": <id>, "role": ...},
    {"user": <id>, "role": ...},
    {"user": <id>, "role": ...},
  ]
}

and then hoping to just expand the user elements is not possible, because we would end up with

{
  "moderators": {
    "data": [
      {"user": <user resource>, "role": ...},
      {"user": <user resource>, "role": ...},
      {"user": <user resource>, "role": ...}
    ]
  }
}

This would include the required information, but result in a different structure.

At the moment, I'm tinkering with either switching to a different embedding style alltogether or at least allowing to change it. Instead of "expanding" the resources in-place, we could put the users aside in the response, like this:

{
  "data": {
    "moderators": {
      "<user id>": "role",
      "<user id>": "role",
      "<user id>": "role",
      "<user id>": "role",
    }
  },
  "linked": {
    "moderators": [
      {user object},
      {user object},
      {user object},
      {user object},
    ]
  }
}

This would elimate redundant output (in this case, there is no redundancy, as each user can only be a moderator once for any given game, but think of /games?embed=moderators, where the same user might be present multiple times in the JSON output) and keep the structure of resources stable, hence solving the problem of information loss in this case.