open_lark/service/search/v2/schema/
mod.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 core::{
6 api_req::ApiRequest,
7 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
8 config::Config,
9 constants::AccessTokenType,
10 endpoints::{EndpointBuilder, Endpoints},
11 http::Transport,
12 req_option::RequestOption,
13 SDKResult,
14 },
15 service::search::v2::models::{CreateSchemaRequest, Schema, UpdateSchemaRequest},
16};
17
18pub struct SchemaService {
20 pub config: Config,
21}
22
23#[derive(Debug, Serialize, Deserialize)]
25pub struct CreateSchemaResponse {
26 pub schema: Schema,
28}
29
30impl ApiResponseTrait for CreateSchemaResponse {
31 fn data_format() -> ResponseFormat {
32 ResponseFormat::Data
33 }
34}
35
36#[derive(Debug, Serialize, Deserialize)]
38pub struct GetSchemaResponse {
39 pub schema: Schema,
41}
42
43impl ApiResponseTrait for GetSchemaResponse {
44 fn data_format() -> ResponseFormat {
45 ResponseFormat::Data
46 }
47}
48
49#[derive(Debug, Serialize, Deserialize)]
51pub struct UpdateSchemaResponse {
52 pub schema: Schema,
54}
55
56impl ApiResponseTrait for UpdateSchemaResponse {
57 fn data_format() -> ResponseFormat {
58 ResponseFormat::Data
59 }
60}
61
62#[derive(Debug, Serialize, Deserialize)]
64pub struct EmptySchemaResponse {}
65
66impl ApiResponseTrait for EmptySchemaResponse {
67 fn data_format() -> ResponseFormat {
68 ResponseFormat::Data
69 }
70}
71
72impl SchemaService {
73 pub fn new(config: Config) -> Self {
74 Self { config }
75 }
76
77 pub async fn create(
91 &self,
92 data_source_id: &str,
93 request: CreateSchemaRequest,
94 option: Option<RequestOption>,
95 ) -> SDKResult<BaseResponse<CreateSchemaResponse>> {
96 let api_req = ApiRequest {
97 http_method: Method::POST,
98 api_path: EndpointBuilder::replace_param(
99 Endpoints::SEARCH_V2_SCHEMA_CREATE,
100 "data_source_id",
101 data_source_id,
102 ),
103 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
104 body: serde_json::to_vec(&request)?,
105 ..Default::default()
106 };
107
108 Transport::request(api_req, &self.config, option).await
109 }
110
111 pub async fn delete(
121 &self,
122 data_source_id: &str,
123 schema_id: &str,
124 option: Option<RequestOption>,
125 ) -> SDKResult<BaseResponse<EmptySchemaResponse>> {
126 let api_req = ApiRequest {
127 http_method: Method::DELETE,
128 api_path: EndpointBuilder::replace_params_from_array(
129 Endpoints::SEARCH_V2_SCHEMA_OPERATION,
130 &[("data_source_id", data_source_id), ("schema_id", schema_id)],
131 ),
132 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
133 ..Default::default()
134 };
135
136 Transport::request(api_req, &self.config, option).await
137 }
138
139 pub async fn patch(
150 &self,
151 data_source_id: &str,
152 schema_id: &str,
153 request: UpdateSchemaRequest,
154 option: Option<RequestOption>,
155 ) -> SDKResult<BaseResponse<UpdateSchemaResponse>> {
156 let api_req = ApiRequest {
157 http_method: Method::PATCH,
158 api_path: EndpointBuilder::replace_params_from_array(
159 Endpoints::SEARCH_V2_SCHEMA_OPERATION,
160 &[("data_source_id", data_source_id), ("schema_id", schema_id)],
161 ),
162 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
163 body: serde_json::to_vec(&request)?,
164 ..Default::default()
165 };
166
167 Transport::request(api_req, &self.config, option).await
168 }
169
170 pub async fn get(
180 &self,
181 data_source_id: &str,
182 schema_id: &str,
183 option: Option<RequestOption>,
184 ) -> SDKResult<BaseResponse<GetSchemaResponse>> {
185 let api_req = ApiRequest {
186 http_method: Method::GET,
187 api_path: EndpointBuilder::replace_params_from_array(
188 Endpoints::SEARCH_V2_SCHEMA_OPERATION,
189 &[("data_source_id", data_source_id), ("schema_id", schema_id)],
190 ),
191 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
192 ..Default::default()
193 };
194
195 Transport::request(api_req, &self.config, option).await
196 }
197}