use openlark_core::{
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
http::Transport,
req_option::RequestOption,
SDKResult,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct UserDeleteRequest {
config: Arc<Config>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserDeleteResponse {
pub data: Option<serde_json::Value>,
}
impl ApiResponseTrait for UserDeleteResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl UserDeleteRequest {
pub fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub async fn execute(self) -> SDKResult<UserDeleteResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<UserDeleteResponse> {
let path = "/open-apis/security/acs/v1/user/delete"
.replace("application", "application")
.replace("security", "acs")
.replace("personal_settings", "personal_settings");
let req: ApiRequest<UserDeleteResponse> = ApiRequest::get(&path);
let resp = Transport::request(req, &self.config, Some(option)).await?;
resp.data.ok_or_else(|| {
openlark_core::error::validation_error("user delete", "响应数据为空")
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json;
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}