2025-03-22 22:17:47 -04:00
|
|
|
pub mod auth;
|
2025-03-23 18:03:11 -04:00
|
|
|
pub mod journal;
|
2025-03-24 20:19:12 -04:00
|
|
|
pub mod journal_permissions;
|
2025-03-23 16:37:43 -04:00
|
|
|
pub mod permissions;
|
2025-03-24 22:42:33 -04:00
|
|
|
pub mod reactions;
|
2025-03-23 18:03:11 -04:00
|
|
|
|
2025-03-22 22:17:47 -04:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct ApiReturn<T>
|
|
|
|
where
|
|
|
|
T: Serialize,
|
|
|
|
{
|
|
|
|
pub ok: bool,
|
|
|
|
pub message: String,
|
|
|
|
pub payload: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2025-03-23 18:03:11 -04:00
|
|
|
MiscError(String),
|
2025-03-22 22:17:47 -04:00
|
|
|
DatabaseConnection(String),
|
|
|
|
UserNotFound,
|
2025-03-23 18:03:11 -04:00
|
|
|
GeneralNotFound(String),
|
2025-03-22 22:17:47 -04:00
|
|
|
RegistrationDisabled,
|
|
|
|
DatabaseError(String),
|
|
|
|
IncorrectPassword,
|
2025-03-23 16:37:43 -04:00
|
|
|
NotAllowed,
|
2025-03-22 22:17:47 -04:00
|
|
|
AlreadyAuthenticated,
|
|
|
|
DataTooLong(String),
|
|
|
|
DataTooShort(String),
|
|
|
|
Unknown,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Error {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
2025-03-23 18:03:11 -04:00
|
|
|
Self::MiscError(msg) => msg.to_owned(),
|
2025-03-23 16:37:43 -04:00
|
|
|
Self::DatabaseConnection(msg) => msg.to_owned(),
|
|
|
|
Self::DatabaseError(msg) => format!("Database error: {msg}"),
|
|
|
|
Self::UserNotFound => "Unable to find user with given parameters".to_string(),
|
2025-03-23 18:03:11 -04:00
|
|
|
Self::GeneralNotFound(name) => format!("Unable to find requested {name}"),
|
2025-03-23 16:37:43 -04:00
|
|
|
Self::RegistrationDisabled => "Registration is disabled".to_string(),
|
|
|
|
Self::IncorrectPassword => "The given password is invalid".to_string(),
|
|
|
|
Self::NotAllowed => "You are not allowed to do this".to_string(),
|
|
|
|
Self::AlreadyAuthenticated => "Already authenticated".to_string(),
|
|
|
|
Self::DataTooLong(name) => format!("Given {name} is too long!"),
|
|
|
|
Self::DataTooShort(name) => format!("Given {name} is too short!"),
|
2025-03-22 22:17:47 -04:00
|
|
|
_ => format!("An unknown error as occurred: ({:?})", self),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Into<ApiReturn<T>> for Error
|
|
|
|
where
|
|
|
|
T: Default + Serialize,
|
|
|
|
{
|
|
|
|
fn into(self) -> ApiReturn<T> {
|
|
|
|
ApiReturn {
|
|
|
|
ok: false,
|
|
|
|
message: self.to_string(),
|
|
|
|
payload: T::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|