use openlark_core::{
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
http::Transport,
req_option::RequestOption,
validate_required, SDKResult,
};
use serde::{Deserialize, Serialize};
use crate::common::{api_endpoints::WikiApiV2, api_utils::*};
pub struct UpdateWikiSpaceNodeTitleRequest {
space_id: String,
node_token: String,
config: Config,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateWikiSpaceNodeTitleParams {
pub title: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct UpdateWikiSpaceNodeTitleResponse {}
impl ApiResponseTrait for UpdateWikiSpaceNodeTitleResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl UpdateWikiSpaceNodeTitleRequest {
pub fn new(config: Config) -> Self {
Self {
space_id: String::new(),
node_token: String::new(),
config,
}
}
pub fn space_id(mut self, space_id: impl Into<String>) -> Self {
self.space_id = space_id.into();
self
}
pub fn node_token(mut self, node_token: impl Into<String>) -> Self {
self.node_token = node_token.into();
self
}
pub async fn execute(
self,
params: UpdateWikiSpaceNodeTitleParams,
) -> SDKResult<UpdateWikiSpaceNodeTitleResponse> {
self.execute_with_options(params, RequestOption::default())
.await
}
pub async fn execute_with_options(
self,
params: UpdateWikiSpaceNodeTitleParams,
option: RequestOption,
) -> SDKResult<UpdateWikiSpaceNodeTitleResponse> {
validate_required!(self.space_id, "知识空间ID不能为空");
validate_required!(self.node_token, "节点Token不能为空");
validate_required!(params.title, "节点标题不能为空");
let api_endpoint =
WikiApiV2::SpaceNodeUpdateTitle(self.space_id.clone(), self.node_token.clone());
let api_request: ApiRequest<UpdateWikiSpaceNodeTitleResponse> =
ApiRequest::post(&api_endpoint.to_url())
.body(serialize_params(¶ms, "更新知识空间节点标题")?);
let response = Transport::request(api_request, &self.config, Some(option)).await?;
extract_response_data(response, "更新知识空间节点标题")
}
}
#[cfg(test)]
mod tests {
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).unwrap();
assert_eq!(value["field"], "data");
}
}