brass/web/src/models/user_funtion.rs

48 lines
1.1 KiB
Rust

use std::fmt::Display;
use serde::Serialize;
use sqlx::postgres::{PgHasArrayType, PgTypeInfo};
use super::Function;
#[derive(sqlx::Type, Debug, Clone, PartialEq, Eq, Serialize, PartialOrd, Ord)]
#[sqlx(no_pg_array)]
pub struct UserFunction(Vec<Function>);
impl PgHasArrayType for UserFunction {
fn array_type_info() -> PgTypeInfo {
PgTypeInfo::with_name("function[]")
}
}
impl Display for UserFunction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut iterator = self.0.iter().peekable();
while let Some(p) = iterator.next() {
write!(f, "{}", p.to_string())?;
if iterator.peek().is_some() {
write!(f, ", ")?;
}
}
Ok(())
}
}
impl UserFunction {
pub fn contains(&self, f: &Function) -> bool {
self.0.contains(f)
}
pub fn is_posten(&self) -> bool {
self.0.contains(&Function::Posten)
}
pub fn is_fuehrungsassistent(&self) -> bool {
self.0.contains(&Function::Fuehrungsassistent)
}
pub fn is_wachhabender(&self) -> bool {
self.0.contains(&Function::Wachhabender)
}
}