open_lark/service/cloud_docs/sheets/v3/data_operation/
find_cells.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 core::{
5 api_req::ApiRequest,
6 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
7 constants::AccessTokenType,
8 req_option, SDKResult,
9 },
10 impl_executable_builder_owned,
11 service::sheets::v3::{
12 data_operation::{FindCondition, FindReplaceResult},
13 SpreadsheetSheetService,
14 },
15};
16
17#[derive(Serialize, Debug, Default)]
18pub struct FindCellsRequest {
19 #[serde(skip)]
20 api_request: ApiRequest,
21 #[serde(skip)]
22 spreadsheet_token: String,
23 #[serde(skip)]
25 sheet_id: String,
26 find_condition: FindCondition,
28 find: String,
35}
36
37impl FindCellsRequest {
38 pub fn builder() -> FindCellsRequestBuilder {
39 FindCellsRequestBuilder::default()
40 }
41}
42
43#[derive(Default)]
44pub struct FindCellsRequestBuilder {
45 request: FindCellsRequest,
46}
47
48impl FindCellsRequestBuilder {
49 pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
50 self.request.spreadsheet_token = spreadsheet_token.to_string();
51 self
52 }
53
54 pub fn sheet_id(mut self, sheet_id: impl ToString) -> Self {
55 self.request.sheet_id = sheet_id.to_string();
56 self
57 }
58
59 pub fn find(mut self, find: impl ToString) -> Self {
60 self.request.find = find.to_string();
61 self
62 }
63
64 pub fn range(mut self, range: impl ToString) -> Self {
65 self.request.find_condition.range = range.to_string();
66 self
67 }
68
69 pub fn match_case(mut self, match_case: bool) -> Self {
70 self.request.find_condition.match_case = Some(match_case);
71 self
72 }
73
74 pub fn match_entire_cell(mut self, match_entire_cell: bool) -> Self {
75 self.request.find_condition.match_entire_cell = Some(match_entire_cell);
76 self
77 }
78
79 pub fn search_by_regex(mut self, search_by_regex: bool) -> Self {
80 self.request.find_condition.search_by_regex = Some(search_by_regex);
81 self
82 }
83
84 pub fn include_formulas(mut self, include_formulas: bool) -> Self {
85 self.request.find_condition.include_formulas = Some(include_formulas);
86 self
87 }
88
89 pub fn build(mut self) -> FindCellsRequest {
90 self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
91 self.request
92 }
93}
94
95impl_executable_builder_owned!(
97 FindCellsRequestBuilder,
98 SpreadsheetSheetService,
99 FindCellsRequest,
100 BaseResponse<FindCellsResponse>,
101 find_cells
102);
103
104#[derive(Deserialize, Debug)]
106pub struct FindCellsResponse {
107 pub find_result: FindReplaceResult,
109}
110
111impl ApiResponseTrait for FindCellsResponse {
112 fn data_format() -> ResponseFormat {
113 ResponseFormat::Data
114 }
115}
116
117impl SpreadsheetSheetService {
118 pub async fn find_cells(
120 &self,
121 request: FindCellsRequest,
122 option: Option<req_option::RequestOption>,
123 ) -> SDKResult<BaseResponse<FindCellsResponse>> {
124 let mut api_req = request.api_request;
125 api_req.api_path = format!(
126 "/open-apis/sheets/v3/spreadsheets/{spreadsheet_token}/sheets/{sheet_id}/find",
127 spreadsheet_token = request.spreadsheet_token,
128 sheet_id = request.sheet_id
129 );
130 api_req.http_method = reqwest::Method::POST;
131 api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::App];
132
133 let api_resp = crate::core::http::Transport::request(api_req, &self.config, option).await?;
134
135 Ok(api_resp)
136 }
137}