fishpi_sdk/client/
reaction.rs1use crate::client::core::FishPi;
2use crate::domain::reaction::ReactionMutationResult;
3use crate::ids::{ArticleId, CommentId, MessageId};
4use crate::utils::error::Error;
5use crate::wire::reaction::WireReactionMutationResult;
6use serde_json::json;
7
8pub struct ReactionApi(pub(crate) FishPi);
10
11impl FishPi {
12 pub fn reaction(&self) -> ReactionApi {
14 ReactionApi(self.clone())
15 }
16}
17
18impl ReactionApi {
19 pub async fn article(
20 &self,
21 article_id: impl Into<ArticleId>,
22 value: impl Into<String>,
23 ) -> Result<ReactionMutationResult, Error> {
24 let article_id = article_id.into();
25 let value = value.into();
26 let wire: WireReactionMutationResult = self
27 .0
28 .post_data(
29 "article/reaction",
30 &json!({
31 "articleId": article_id.as_str(),
32 "groupType": "emoji",
33 "value": value,
34 }),
35 )
36 .await?;
37 Ok(wire.into())
38 }
39
40 pub async fn comment(
41 &self,
42 comment_id: impl Into<CommentId>,
43 value: impl Into<String>,
44 ) -> Result<ReactionMutationResult, Error> {
45 let comment_id = comment_id.into();
46 let value = value.into();
47 let wire: WireReactionMutationResult = self
48 .0
49 .post_data(
50 "comment/reaction",
51 &json!({
52 "commentId": comment_id.as_str(),
53 "groupType": "emoji",
54 "value": value,
55 }),
56 )
57 .await?;
58 Ok(wire.into())
59 }
60
61 pub async fn chat_room(
62 &self,
63 o_id: impl Into<MessageId>,
64 value: impl Into<String>,
65 ) -> Result<ReactionMutationResult, Error> {
66 let o_id = o_id.into();
67 let value = value.into();
68 let wire: WireReactionMutationResult = self
69 .0
70 .post_data(
71 "chat-room/reaction",
72 &json!({
73 "oId": o_id.as_str(),
74 "groupType": "emoji",
75 "value": value,
76 }),
77 )
78 .await?;
79 Ok(wire.into())
80 }
81}