Skip to main content

User features

User custom data

Overview

This feature allow third party apps to save custom data into user database

Properties

FieldTypeDescription
data_keyString(92)Data key, can be a path with dot separation
data_groupString(92)Feature group name
data_valuejsonbJson data
user_idint64price per item in quantity.

APIs

VERDEndpointParametersDataResponseDesc
GET/api/user-data/get-one-by-keyuserId, dataKeyUserDataFind a data key for specific user, throw HTTP 404 if not found
POST/api/user-data/find-one-by-keyUserDataKeyDtoUserDataFind a data key for specific user
POST/api/user-data/find-many-by-groupUserDataGroupDtoUserData[]Find many data by group for specific user
POST/api/user-data/save-one-by-key/:userId/:dataKeyUserDataSaveDtoUserDataSave or update with data key for specific user
export class UserDataKeyDto {
// Data key, no need to unique, (userId, dataKey) must be unique
dataKey: string;

// User id
userId: string;
}

export class UserDataGroupDto {
// Data key, no need to unique
dataGroup: string;

// User id
userId: string;
}

export class UserDataValueDto {
// Data key, no need to unique, (userId, dataKey) must be unique
dataKey: string;

// User id
userId: string;

// Full update, previous data will be overwrited
dataValue?: any;

// Partial update, only update provide fields, other fields is untouched
partialDataValue?: any;
}

Usage examples

  1. Store data for a game/app for user id 'user1' when user is first created

Call POST /api/user-data/save-one-by-key/

With data

{
"userId": "user1",
"dataGroup": "basic",
"dataKey": "user-profile",
"dataValue": {
"level": 1,
"displayName": "Hello"
}
}
  1. Later update some attribute as user progress

Call POST /api/user-data/save-one-by-key/

With data

{
"userId": "user1",
"dataKey": "user-profile",
"partialDataValue": {
"level": 2
}
}
  1. Retreive data to display on UI

Call GET /api/user-data/get-one-by-key/user1/user-profile

Response data

{
"userId": "user1",
"dataKey": "user-profile",
"dataGroup": "basic",
"dataValue": {
"level": 2,
"displayName": "Hello"
}
//... other data
}
  1. Retreive all data from a feature group

Call GET /api/user-data/find-many-by-group

With data

{
"userId": "user1",
"dataGroup": "basic"
}

Response data

[
{
"userId": "user1",
"dataGroup": "basic",
"dataKey": "user-profile",
"dataValue": {
"level": 2,
"displayName": "Hello"
}
//... other data
},
{
"userId": "user1",
"dataGroup": "basic"
//... other data
}
]

Tips and tricks

  • Try to group data as must as possiple to reduce records generation which will impact performance
  • Try to make data value small enough for a single atomic feature, since update method is not thread safe, if store very large object into as single data will cause data inconsistancy for highload environment
  • Summary, how to break and how to merge data need to be balanced