1
user
Interitio edited this page 2025-06-18 19:33:50 +10:00

User

Represents a twitch user.

field type required description
user_id integer - Internal UID of this user. (NOT the twitch userid)
twitch_id string? yes Twitch user-id for this user. Stored as a string.
name string? yes Twitch name for this user. May not be up to date.
created_at timestamp - When this user was created (internally). Automatically set on creation.
preferences string? no Arbitrary preference string, not used or read.

// The name is stored mainly for easy visual reference/convenience when debugging, and should not be relied on.

Note that the twitch_id and name parameters are best-effort and there are some rare cases where they are unreliable:

  • If a user linked their twitch account to Discord, and then unlinked the twitch account or deleted it, then twitch_id and name may be null.

  • If a user linked multiple twitch accounts, then the returned twitch_id and name will only be for one account.

    • In this rare case, filter parameters will still fetch the correct user. This may lead to technically unexpected behaviour, for example:
      • Assume a user with user_id 10 has linked twitch account 1 and later twitch account 2.
      • Then both GET /users?twitch_id=2 and GET /users?twitch_id=1 will return {"user_id": 10, "twitch_id": 1}.
  • Due to the general ephemeral nature of names, it is not recommended to rely on the name field in any way. It is included mainly for ease of debugging and reference.

  • Currently there is no way of retrieving all the twitch accounts associated to a user. Is this needed?

  • POST /users

    • Create and return a User
  • GET /users

    • Get all Users matching the given parameters
    • Supported filter parameters:
      • user_id
      • twitch_id
      • name - Supported, but should not typically be used.
      • created_after
      • created_before
  • GET /users/{user_id}

    • Get the UserDetails for the given user.
  • PATCH /users/{user_id}

    • Updates the given User
    • Supports updating name and preferences.
    • Intended to be extended to update other preference fields in future.
    • Returns the updated User
  • DELETE /users/{user_id}

    • Deletes the given user, and all associated data. This includes:
      • All Events associated to the user (cascading as in DELETE /events/{event_id})
      • All Specimens associated to the user.
      • All InventoryItems owned by the user.
      • All Transactions made by the user.
    • Returns UserDetails of the deleted user.
  • * /users/{user_id}/events

    • Inherits all /events routes with user_id set.
  • * /users/{user_id}/specimen

    • If the action is POST, will create and return a Specimen for this user.
      • Note that this will error if the user already has an active specimen.
    • Otherwise inherits the /specimens/{specimen_id} with specimen_id set to the user's active specimen.
      • If the user does not have an active Specimen this will raise NotFound.
  • * /user/{user_id}/specimens

    • Inherits all /specimens routes with the owner_id set to user_id.
  • GET /users/{user_id}/wallet

    • Will return the current amount in the user's wallet.
    • Not typically used and only included for route consistency.
  • * /users/{user_id}/transactions

    • Inherits all routes from the /transactions route, with user_id set.

UserDetails

This is a convenience model presenting the current natural 'state' of the user, including their current Specimen, their wallet, and their current inventory.

This is the model returned by GET /users. Note that the specimen, inventory, and wallet fields cannot be set or updated directly, instead use /users/{user_id}/specimen, /users/{user_id}/inventory, and /users/{user_id}/transactions respectively. The wallet is viewable from /users/{user_id}/wallet, but does not support direct updates. (All updates must occur through transactions.)

In addition to the fields from User, this model has the following fields

field type required description
specimen Specimen? - Current living specimen for this user if it exists.
inventory [InventoryItem] - List of active inventory items for this user.
wallet integer - How much currency the user currently has.