yggdrasil/api/comments/
types.rs1use crate::models::comment::{AdminComment, PublicComment};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct CommentResponse {
9 pub success: bool,
11 pub message: String,
13 pub error_code: Option<String>,
15 #[serde(default)]
17 pub comment_id: Option<i64>,
18 #[serde(default)]
20 pub avatar_url: Option<String>,
21 #[serde(default)]
23 pub depth: Option<i32>,
24}
25
26#[cfg_attr(not(feature = "server"), allow(dead_code))]
29impl CommentResponse {
30 pub fn error(error_code: &str, message: impl Into<String>) -> Self {
32 Self {
33 success: false,
34 message: message.into(),
35 error_code: Some(error_code.into()),
36 comment_id: None,
37 avatar_url: None,
38 depth: None,
39 }
40 }
41
42 pub fn ok(message: impl Into<String>) -> Self {
44 Self {
45 success: true,
46 message: message.into(),
47 error_code: None,
48 comment_id: None,
49 avatar_url: None,
50 depth: None,
51 }
52 }
53
54 pub fn created(
56 message: impl Into<String>,
57 comment_id: i64,
58 avatar_url: impl Into<String>,
59 depth: i32,
60 ) -> Self {
61 Self {
62 success: true,
63 message: message.into(),
64 error_code: None,
65 comment_id: Some(comment_id),
66 avatar_url: Some(avatar_url.into()),
67 depth: Some(depth),
68 }
69 }
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct CommentTreeResponse {
75 pub comments: Vec<PublicComment>,
77 pub count: i64,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct AllCommentsResponse {
84 pub comments: Vec<AdminComment>,
86 pub total: i64,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct PendingCountResponse {
93 pub count: i64,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct BatchStatusResponse {
100 pub success: bool,
102 pub updated_count: i64,
104 pub message: String,
106}