open_lark/service/cloud_docs/sheets/v3/float_image/
query.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 core::{
6 api_req::ApiRequest,
7 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
8 constants::AccessTokenType,
9 endpoints::cloud_docs::*,
10 http::Transport,
11 req_option::RequestOption,
12 SDKResult,
13 },
14 impl_executable_builder_owned,
15 service::sheets::v3::SpreadsheetSheetService,
16};
17
18use super::get::FloatImageInfo;
19
20impl SpreadsheetSheetService {
21 pub async fn query_float_images(
23 &self,
24 request: QueryFloatImagesRequest,
25 option: Option<RequestOption>,
26 ) -> SDKResult<BaseResponse<QueryFloatImagesResponseData>> {
27 let mut api_req = request.api_request;
28 api_req.http_method = Method::GET;
29 api_req.api_path = SHEETS_V3_SPREADSHEET_FLOAT_IMAGES
30 .replace("{}", &request.spreadsheet_token)
31 .replace("{}", &request.sheet_id);
32 api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::User];
33
34 let api_resp = Transport::request(api_req, &self.config, option).await?;
35
36 Ok(api_resp)
37 }
38}
39
40#[derive(Default, Debug, Serialize, Deserialize)]
42pub struct QueryFloatImagesRequest {
43 #[serde(skip)]
44 api_request: ApiRequest,
45 spreadsheet_token: String,
47 sheet_id: String,
49}
50
51impl QueryFloatImagesRequest {
52 pub fn builder() -> QueryFloatImagesRequestBuilder {
53 QueryFloatImagesRequestBuilder::default()
54 }
55}
56
57#[derive(Default)]
58pub struct QueryFloatImagesRequestBuilder {
59 request: QueryFloatImagesRequest,
60}
61
62impl QueryFloatImagesRequestBuilder {
63 pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
64 self.request.spreadsheet_token = spreadsheet_token.to_string();
65 self
66 }
67
68 pub fn sheet_id(mut self, sheet_id: impl ToString) -> Self {
69 self.request.sheet_id = sheet_id.to_string();
70 self
71 }
72
73 pub fn build(mut self) -> QueryFloatImagesRequest {
74 self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
75 self.request
76 }
77}
78
79impl_executable_builder_owned!(
80 QueryFloatImagesRequestBuilder,
81 SpreadsheetSheetService,
82 QueryFloatImagesRequest,
83 BaseResponse<QueryFloatImagesResponseData>,
84 query_float_images
85);
86
87#[derive(Deserialize, Debug)]
89pub struct QueryFloatImagesResponseData {
90 pub items: Vec<FloatImageInfo>,
92 #[serde(default)]
94 pub has_more: bool,
95 #[serde(skip_serializing_if = "Option::is_none")]
97 pub page_token: Option<String>,
98}
99
100impl ApiResponseTrait for QueryFloatImagesResponseData {
101 fn data_format() -> ResponseFormat {
102 ResponseFormat::Data
103 }
104}
105
106#[cfg(test)]
107#[allow(unused_variables, unused_unsafe)]
108mod test {
109 use super::*;
110 use serde_json::json;
111
112 #[test]
113 fn test_query_float_images_response() {
114 let json = json!({
115 "items": [
116 {
117 "float_image_id": "fimg_001",
118 "image_token": "img_token_123",
119 "position": {
120 "start_col_index": 1,
121 "start_row_index": 1,
122 "offset_x": 10.0,
123 "offset_y": 20.0
124 },
125 "size": {
126 "width": 200.0,
127 "height": 150.0
128 },
129 "name": "图片1"
130 },
131 {
132 "float_image_id": "fimg_002",
133 "image_token": "img_token_456",
134 "position": {
135 "start_col_index": 3,
136 "start_row_index": 3,
137 "offset_x": 0.0,
138 "offset_y": 0.0
139 },
140 "size": {
141 "width": 150.0,
142 "height": 100.0
143 },
144 "name": "图片2"
145 }
146 ],
147 "has_more": false
148 });
149
150 let response: QueryFloatImagesResponseData = serde_json::from_value(json).unwrap();
151 assert_eq!(response.items.len(), 2);
152 assert_eq!(response.items[0].float_image_id, "fimg_001");
153 assert_eq!(response.items[1].float_image.image_token, "img_token_456");
154 assert!(!response.has_more);
155 }
156}