lan-party-backend/core/src/util.rs

45 lines
1.2 KiB
Rust

#[cfg(feature = "rocket")]
use rocket::FromFormField;
#[cfg(feature = "openapi")]
use schemars::JsonSchema;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum PartyError {
#[error("user `{0}` does not exist")]
UserNotFound(String),
#[error("event `{0}` does not exist")]
EventNotFound(String),
#[error("unknown error: {0}")]
Unknown(String),
#[error("invalid parameter: {0}")]
InvalidParameter(String),
}
/// # Ordering
///
/// Ordering of data in an array, ascending or descending
#[derive(Clone, Debug)]
#[cfg_attr(feature = "openapi", derive(JsonSchema))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rocket", derive(FromFormField))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Ordering {
#[cfg_attr(feature = "rocket", field(value = "desc"))]
Desc,
#[cfg_attr(feature = "rocket", field(value = "asc"))]
Asc,
}
impl ToString for Ordering {
fn to_string(&self) -> String {
match self {
Self::Desc => "DESC",
Self::Asc => "ASC",
}
.into()
}
}