tetratto_core2/model/
mod.rs1pub mod addr;
2pub mod apps;
3pub mod auth;
4pub mod carp;
5pub mod groups;
6pub mod id;
7pub mod moderation;
8pub mod oauth;
9pub mod permissions;
10pub mod posts;
11pub mod reactions;
12pub mod requests;
13pub mod socket;
14
15use std::fmt::Display;
16use serde::{Deserialize, Serialize};
17
18#[derive(Serialize, Deserialize)]
19pub struct ApiReturn<T>
20where
21 T: Serialize,
22{
23 pub ok: bool,
24 pub message: String,
25 pub payload: T,
26}
27
28#[derive(Debug)]
29pub enum Error {
30 MiscError(String),
31 DatabaseConnection(String),
32 UserNotFound,
33 GeneralNotFound(String),
34 RegistrationDisabled,
35 DatabaseError(String),
36 IncorrectPassword,
37 NotAllowed,
38 AlreadyAuthenticated,
39 DataTooLong(String),
40 DataTooShort(String),
41 FileTooLarge,
42 FileTooSmall,
43 UsernameInUse,
44 TitleInUse,
45 QuestionsDisabled,
46 RequiresSupporter,
47 DrawingsDisabled,
48 AppHitStorageLimit,
49 DoesNotSupportField(String),
50 Unknown,
51}
52
53impl Display for Error {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 f.write_str(&match self {
56 Self::MiscError(msg) => msg.to_owned(),
57 Self::DatabaseConnection(msg) => msg.to_owned(),
58 Self::DatabaseError(msg) => format!("Database error: {msg}"),
59 Self::UserNotFound => "Unable to find user with given parameters".to_string(),
60 Self::GeneralNotFound(name) => format!("Unable to find requested {name}"),
61 Self::RegistrationDisabled => "Registration is disabled".to_string(),
62 Self::IncorrectPassword => "The given password is invalid".to_string(),
63 Self::NotAllowed => "You are not allowed to do this".to_string(),
64 Self::AlreadyAuthenticated => "Already authenticated".to_string(),
65 Self::DataTooLong(name) => format!("Given {name} is too long!"),
66 Self::DataTooShort(name) => format!("Given {name} is too short!"),
67 Self::FileTooLarge => "Given file is too large".to_string(),
68 Self::FileTooSmall => "Given file is too small".to_string(),
69 Self::UsernameInUse => "Username in use".to_string(),
70 Self::TitleInUse => "Title in use".to_string(),
71 Self::QuestionsDisabled => "You are not allowed to ask questions there".to_string(),
72 Self::RequiresSupporter => "Only site supporters can do this".to_string(),
73 Self::DrawingsDisabled => "You are not allowed to submit drawings there".to_string(),
74 Self::AppHitStorageLimit => "This app has already hit its storage limit, or will do so if this data is processed.".to_string(),
75 Self::DoesNotSupportField(name) => format!("{name} does not support this field"),
76 _ => format!("An unknown error as occurred: ({:?})", self),
77 })
78 }
79}
80
81impl<T> From<Error> for ApiReturn<T>
82where
83 T: Default + Serialize,
84{
85 fn from(val: Error) -> Self {
86 ApiReturn {
87 ok: false,
88 message: val.to_string(),
89 payload: T::default(),
90 }
91 }
92}
93
94pub type Result<T> = std::result::Result<T, Error>;
95
96pub mod uploads {
97 pub use buckets_core::model::{MediaType, MediaUpload};
98}