Nathan.fooo 71f80be8f7
feat: save user metadata (#3754)
* feat: save user metadata

* chore: update client api

* refactor: separate test methods

* chore: save updated at

* chore: clippy

* chore: fix test
2023-10-24 20:11:06 +08:00

83 lines
1.8 KiB
Rust

use std::fmt;
use std::fmt::Display;
use chrono::{DateTime, Utc};
use serde::Deserialize;
use serde_json::Value;
use uuid::Uuid;
use crate::util::deserialize_null_or_default;
pub enum GetUserProfileParams {
Uid(i64),
Uuid(Uuid),
}
#[allow(dead_code)]
#[derive(Debug, Deserialize, Clone)]
pub(crate) struct UserProfileResponse {
pub uid: i64,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub name: String,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub email: String,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub latest_workspace_id: String,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub encryption_sign: String,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Deserialize)]
pub(crate) struct UserProfileResponseList(pub Vec<UserProfileResponse>);
#[derive(Deserialize, Clone)]
pub(crate) struct UidResponse {
#[allow(dead_code)]
pub uid: i64,
}
#[derive(Debug, Deserialize)]
pub struct RealtimeEvent {
pub schema: String,
pub table: String,
#[serde(rename = "eventType")]
pub event_type: String,
pub new: Value,
}
impl Display for RealtimeEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"schema: {}, table: {}, event_type: {}",
self.schema, self.table, self.event_type
)
}
}
#[derive(Debug, Deserialize)]
pub struct RealtimeCollabUpdateEvent {
pub oid: String,
pub uid: i64,
pub key: i64,
pub did: String,
pub value: String,
#[serde(default)]
pub encrypt: i32,
}
#[derive(Debug, Deserialize)]
pub struct RealtimeUserEvent {
pub uid: i64,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub name: String,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub email: String,
#[serde(deserialize_with = "deserialize_null_or_default")]
pub encryption_sign: String,
}