notion_client/endpoints/databases/
update.rs1pub mod request;
2
3use crate::{
4 endpoints::NOTION_URI,
5 objects::{database::Database, Response},
6 NotionClientError,
7};
8
9use self::request::UpdateADatabaseRequest;
10
11use super::DatabasesEndpoint;
12
13impl DatabasesEndpoint {
14 pub async fn update_a_database(
15 &self,
16 database_id: &str,
17 request: UpdateADatabaseRequest,
18 ) -> Result<Database, NotionClientError> {
19 let json = serde_json::to_string(&request)
20 .map_err(|e| NotionClientError::FailedToSerialize { source: e })?;
21
22 let result = self
23 .client
24 .post(format!(
25 "{notion_uri}/databases/{database_id}",
26 notion_uri = NOTION_URI,
27 database_id = database_id
28 ))
29 .body(json)
30 .send()
31 .await
32 .map_err(|e| NotionClientError::FailedToRequest { source: e })?;
33
34 let body = result
35 .text()
36 .await
37 .map_err(|e| NotionClientError::FailedToText { source: e })?;
38
39 let response = serde_json::from_str(&body)
40 .map_err(|e| NotionClientError::FailedToDeserialize { source: e, body })?;
41
42 match response {
43 Response::Success(r) => Ok(r),
44 Response::Error(e) => Err(NotionClientError::InvalidStatusCode { error: e }),
45 }
46 }
47}