open_lark/service/cloud_docs/sheets/v3/data_operation/
replace_cells.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 core::{
5 api_req::ApiRequest,
6 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
7 constants::AccessTokenType,
8 endpoints::cloud_docs::*,
9 req_option,
10 standard_response::StandardResponse,
11 SDKResult,
12 },
13 impl_executable_builder_owned,
14 service::sheets::v3::{
15 data_operation::{FindCondition, FindReplaceResult},
16 SpreadsheetSheetService,
17 },
18};
19
20#[derive(Serialize, Debug, Default)]
21pub struct ReplaceCellsRequest {
22 #[serde(skip)]
23 api_request: ApiRequest,
24 #[serde(skip)]
25 spreadsheet_token: String,
26 #[serde(skip)]
28 sheet_id: String,
29 find_condition: FindCondition,
31 find: String,
38 replacement: String,
40}
41
42impl ReplaceCellsRequest {
43 pub fn builder() -> ReplaceCellsRequestBuilder {
44 ReplaceCellsRequestBuilder::default()
45 }
46}
47
48#[derive(Default)]
49pub struct ReplaceCellsRequestBuilder {
50 request: ReplaceCellsRequest,
51}
52
53impl ReplaceCellsRequestBuilder {
54 pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
55 self.request.spreadsheet_token = spreadsheet_token.to_string();
56 self
57 }
58
59 pub fn sheet_id(mut self, sheet_id: impl ToString) -> Self {
60 self.request.sheet_id = sheet_id.to_string();
61 self
62 }
63
64 pub fn find(mut self, find: impl ToString) -> Self {
65 self.request.find = find.to_string();
66 self
67 }
68
69 pub fn range(mut self, range: impl ToString) -> Self {
70 self.request.find_condition.range = range.to_string();
71 self
72 }
73
74 pub fn match_case(mut self, match_case: bool) -> Self {
75 self.request.find_condition.match_case = Some(match_case);
76 self
77 }
78
79 pub fn match_entire_cell(mut self, match_entire_cell: bool) -> Self {
80 self.request.find_condition.match_entire_cell = Some(match_entire_cell);
81 self
82 }
83
84 pub fn search_by_regex(mut self, search_by_regex: bool) -> Self {
85 self.request.find_condition.search_by_regex = Some(search_by_regex);
86 self
87 }
88
89 pub fn include_formulas(mut self, include_formulas: bool) -> Self {
90 self.request.find_condition.include_formulas = Some(include_formulas);
91 self
92 }
93
94 pub fn replacement(mut self, replacement: impl ToString) -> Self {
95 self.request.replacement = replacement.to_string();
96 self
97 }
98
99 pub fn build(mut self) -> ReplaceCellsRequest {
100 self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
101 self.request
102 }
103}
104
105impl_executable_builder_owned!(
107 ReplaceCellsRequestBuilder,
108 SpreadsheetSheetService,
109 ReplaceCellsRequest,
110 ReplaceCellsResponse,
111 replace_cells
112);
113
114#[derive(Deserialize, Debug)]
116pub struct ReplaceCellsResponse {
117 pub replace_result: FindReplaceResult,
119}
120
121impl ApiResponseTrait for ReplaceCellsResponse {
122 fn data_format() -> ResponseFormat {
123 ResponseFormat::Data
124 }
125}
126
127impl SpreadsheetSheetService {
128 pub async fn replace_cells(
134 &self,
135 request: ReplaceCellsRequest,
136 option: Option<req_option::RequestOption>,
137 ) -> SDKResult<ReplaceCellsResponse> {
138 let mut api_req = request.api_request;
139 api_req.api_path = SHEETS_V3_SPREADSHEET_SHEET_REPLACE
140 .replace("{}", &request.spreadsheet_token)
141 .replace("{}", &request.sheet_id);
142 api_req.http_method = reqwest::Method::POST;
143 api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::App];
144
145 let api_resp: BaseResponse<ReplaceCellsResponse> =
146 crate::core::http::Transport::request(api_req, &self.config, option).await?;
147 api_resp.into_result()
148 }
149}