files_sdk/files/
file_comments.rs1use crate::{FilesClient, Result};
11use serde::{Deserialize, Serialize};
12use serde_json::json;
13
14#[derive(Debug, Serialize, Deserialize, Clone)]
16pub struct FileCommentEntity {
17 pub id: Option<i64>,
19
20 pub body: Option<String>,
22
23 pub reactions: Option<Vec<FileCommentReactionEntity>>,
25}
26
27#[derive(Debug, Serialize, Deserialize, Clone)]
29pub struct FileCommentReactionEntity {
30 pub id: Option<i64>,
32
33 pub emoji: Option<String>,
35}
36
37#[derive(Debug, Clone)]
39pub struct FileCommentHandler {
40 client: FilesClient,
41}
42
43impl FileCommentHandler {
44 pub fn new(client: FilesClient) -> Self {
46 Self { client }
47 }
48
49 pub async fn list(&self, path: &str) -> Result<Vec<FileCommentEntity>> {
72 let endpoint = format!("/file_comments/files{}", path);
73 let response = self.client.get_raw(&endpoint).await?;
74 Ok(serde_json::from_value(response)?)
75 }
76
77 pub async fn create(&self, path: &str, body: &str) -> Result<FileCommentEntity> {
84 let body_json = json!({
85 "body": body,
86 "path": path,
87 });
88
89 let response = self.client.post_raw("/file_comments", body_json).await?;
90 Ok(serde_json::from_value(response)?)
91 }
92
93 pub async fn update(&self, id: i64, body: &str) -> Result<FileCommentEntity> {
100 let body_json = json!({
101 "body": body,
102 });
103
104 let endpoint = format!("/file_comments/{}", id);
105 let response = self.client.patch_raw(&endpoint, body_json).await?;
106 Ok(serde_json::from_value(response)?)
107 }
108
109 pub async fn delete(&self, id: i64) -> Result<()> {
115 let endpoint = format!("/file_comments/{}", id);
116 self.client.delete_raw(&endpoint).await?;
117 Ok(())
118 }
119
120 pub async fn add_reaction(
127 &self,
128 file_comment_id: i64,
129 emoji: &str,
130 ) -> Result<FileCommentReactionEntity> {
131 let body = json!({
132 "file_comment_id": file_comment_id,
133 "emoji": emoji,
134 });
135
136 let response = self
137 .client
138 .post_raw("/file_comment_reactions", body)
139 .await?;
140 Ok(serde_json::from_value(response)?)
141 }
142
143 pub async fn delete_reaction(&self, id: i64) -> Result<()> {
149 let endpoint = format!("/file_comment_reactions/{}", id);
150 self.client.delete_raw(&endpoint).await?;
151 Ok(())
152 }
153}
154
155#[cfg(test)]
156mod tests {
157 use super::*;
158
159 #[test]
160 fn test_handler_creation() {
161 let client = FilesClient::builder().api_key("test-key").build().unwrap();
162 let _handler = FileCommentHandler::new(client);
163 }
164}