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                endpoint: None,
55                code: status.as_u16(),
56                message: response.text().await.unwrap_or_default(),
57            });
58        }
59
60        let entities: Vec<MessageCommentReactionEntity> = response.json().await?;
61        Ok((entities, pagination))
62    }
63
64    pub async fn get(&self, id: i64) -> Result<MessageCommentReactionEntity> {
65        let endpoint = format!("/message_comment_reactions/{}", id);
66        let response = self.client.get_raw(&endpoint).await?;
67        Ok(serde_json::from_value(response)?)
68    }
69
70    pub async fn create(&self, params: serde_json::Value) -> Result<MessageCommentReactionEntity> {
71        let response = self
72            .client
73            .post_raw("/message_comment_reactions", params)
74            .await?;
75        Ok(serde_json::from_value(response)?)
76    }
77
78    pub async fn delete(&self, id: i64) -> Result<()> {
79        let endpoint = format!("/message_comment_reactions/{}", id);
80        self.client.delete_raw(&endpoint).await?;
81        Ok(())
82    }
83}