45 lines
1.2 KiB
Rust
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};
|
|
|
|
/// # User
|
|
///
|
|
/// A user that represents a person participating in the LAN party
|
|
#[derive(Clone, Debug, Default, PartialEq)]
|
|
#[cfg_attr(feature = "openapi", derive(JsonSchema))]
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
pub struct User {
|
|
/// Name of the user
|
|
pub name: String,
|
|
/// Score of the user
|
|
pub score: i64,
|
|
}
|
|
|
|
/// # UserSort
|
|
///
|
|
/// Field used to sort users
|
|
#[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 UserSort {
|
|
#[cfg_attr(feature = "rocket", field(value = "score"))]
|
|
Score,
|
|
#[cfg_attr(feature = "rocket", field(value = "name"))]
|
|
Name,
|
|
}
|
|
|
|
impl ToString for UserSort {
|
|
fn to_string(&self) -> String {
|
|
match self {
|
|
Self::Score => "score",
|
|
Self::Name => "name",
|
|
}
|
|
.into()
|
|
}
|
|
}
|