webcomment/common/src/api/resps.rs
2023-07-13 11:36:31 +02:00

91 lines
1.9 KiB
Rust

use crate::types::*;
use serde::{Deserialize, Serialize};
/*/// Use Ok only when there is no dedicated struct
/// (because serde doesn't allow flattening enums)
#[derive(Debug, Serialize)]
pub enum Result {
Ok,
#[serde(rename = "error")]
Err(Error),
}*/
pub type Result = std::result::Result<Response, Error>;
#[derive(Debug, Deserialize, Serialize)]
pub enum Error {
Antispam {
timeout: Time,
},
BadAdminAuth,
IllegalContent,
Internal,
InvalidRequest,
/// Admin only! Error messages may contain sensitive information.
Message(String),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum Response {
CommentsByTopic(CommentsByTopic),
CommentsByTopicAdmin(CommentsByTopicAdmin),
NewComment(NewComment),
Ok,
}
/*#[derive(Serialize)]
pub struct GenericOk {}*/
#[derive(Debug, Deserialize, Serialize)]
pub struct CommentsByTopic {
pub approved_comments: Vec<ApprovedCommentWithMeta>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct CommentsByTopicAdmin {
pub approved_comments: Vec<ApprovedCommentWithMeta>,
pub pending_comments: Vec<PendingCommentWithMeta>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct OriginalComment {
pub author: String,
pub editable: bool,
pub last_edit_time: Option<Time>,
pub post_time: Time,
pub text: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ApprovedCommentWithMeta {
pub email: Option<String>,
pub author: String,
pub editable: bool,
pub id: String,
pub last_edit_time: Option<Time>,
pub post_time: Time,
pub status: CommentStatus,
pub text: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct PendingCommentWithMeta {
pub addr: Option<String>,
pub email: Option<String>,
pub author: String,
pub editable: bool,
pub id: String,
pub last_edit_time: Option<Time>,
pub post_time: Time,
pub status: CommentStatus,
pub text: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct NewComment {
pub id: String,
pub mutation_token: String,
pub post_time: Time,
}