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 GetUserRequest {
config: Arc<Config>,
user_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetUserResponse {
pub data: Option<serde_json::Value>,
}
impl ApiResponseTrait for GetUserResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl GetUserRequest {
pub fn new(config: Arc<Config>, user_id: impl Into<String>) -> Self {
Self {
config,
user_id: user_id.into(),
}
}
pub async fn execute(self) -> SDKResult<GetUserResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<GetUserResponse> {
let path = format!("/open-apis/acs/v1/users/{}", self.user_id);
let req: ApiRequest<GetUserResponse> = ApiRequest::get(&path);
let _resp: openlark_core::api::Response<GetUserResponse> =
Transport::request(req, &self.config, Some(option)).await?;
Ok(GetUserResponse { data: None })
}
}
#[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");
}
}