files_sdk/messages/
message_comment_reactions.rs

1use crate::{Result, client::FilesClient, types::PaginationInfo};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct MessageCommentReactionEntity {
6    #[serde(flatten)]
7    pub data: serde_json::Map<String, serde_json::Value>,
8}
9
10pub struct MessageCommentReactionHandler {
11    client: FilesClient,
12}
13
14impl MessageCommentReactionHandler {
15    pub fn new(client: FilesClient) -> Self {
16        Self { client }
17    }
18
19    pub async fn list(
20        &self,
21        message_comment_id: i64,
22        cursor: Option<String>,
23        per_page: Option<i64>,
24    ) -> Result<(Vec<MessageCommentReactionEntity>, PaginationInfo)> {
25        let mut endpoint = "/message_comment_reactions".to_string();
26        let mut query_params = vec![format!("message_comment_id={}", message_comment_id)];
27
28        if let Some(cursor) = cursor {
29            query_params.push(format!("cursor={}", cursor));
30        }
31
32        if let Some(per_page) = per_page {
33            query_params.push(format!("per_page={}", per_page));
34        }
35
36        if !query_params.is_empty() {
37            endpoint.push('?');
38            endpoint.push_str(&query_params.join("&"));
39        }
40
41        let url = format!("{}{}", self.client.inner.base_url, endpoint);
42        let response = reqwest::Client::new()
43            .get(&url)
44            .header("X-FilesAPI-Key", &self.client.inner.api_key)
45            .send()
46            .await?;
47
48        let headers = response.headers().clone();
49        let pagination = PaginationInfo::from_headers(&headers);
50
51        let status = response.status();
52        if !status.is_success() {
53            return Err(crate::FilesError::ApiError {
54                code: status.as_u16(),
55                message: response.text().await.unwrap_or_default(),
56            });
57        }
58
59        let entities: Vec<MessageCommentReactionEntity> = response.json().await?;
60        Ok((entities, pagination))
61    }
62
63    pub async fn get(&self, id: i64) -> Result<MessageCommentReactionEntity> {
64        let endpoint = format!("/message_comment_reactions/{}", id);
65        let response = self.client.get_raw(&endpoint).await?;
66        Ok(serde_json::from_value(response)?)
67    }
68
69    pub async fn create(&self, params: serde_json::Value) -> Result<MessageCommentReactionEntity> {
70        let response = self
71            .client
72            .post_raw("/message_comment_reactions", params)
73            .await?;
74        Ok(serde_json::from_value(response)?)
75    }
76
77    pub async fn delete(&self, id: i64) -> Result<()> {
78        let endpoint = format!("/message_comment_reactions/{}", id);
79        self.client.delete_raw(&endpoint).await?;
80        Ok(())
81    }
82}