User features
User custom data
Overview
This feature allow third party apps to save custom data into user database
Properties
| Field | Type | Description |
|---|---|---|
data_key | String(92) | Data key, can be a path with dot separation |
data_group | String(92) | Feature group name |
data_value | jsonb | Json data |
user_id | int64 | price per item in quantity. |
APIs
| VERD | Endpoint | Parameters | Data | Response | Desc |
|---|---|---|---|---|---|
GET | /api/user-data/get-one-by-key | userId, dataKey | UserData | Find a data key for specific user, throw HTTP 404 if not found | |
POST | /api/user-data/find-one-by-key | UserDataKeyDto | UserData | Find a data key for specific user | |
POST | /api/user-data/find-many-by-group | UserDataGroupDto | UserData[] | Find many data by group for specific user | |
POST | /api/user-data/save-one-by-key/:userId/:dataKey | UserDataSaveDto | UserData | Save 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
- 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"
}
}
- 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
}
}
- 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
}
- 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