Skip to main content

backbone_maintenance/domain/entity/
request_priority.rs

1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "request_priority", rename_all = "snake_case")]
11pub enum RequestPriority {
12    VeryLow,
13    Low,
14    Normal,
15    High,
16}
17
18impl std::fmt::Display for RequestPriority {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::VeryLow => write!(f, "very_low"),
22            Self::Low => write!(f, "low"),
23            Self::Normal => write!(f, "normal"),
24            Self::High => write!(f, "high"),
25        }
26    }
27}
28
29impl FromStr for RequestPriority {
30    type Err = String;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_lowercase().as_str() {
34            "very_low" => Ok(Self::VeryLow),
35            "low" => Ok(Self::Low),
36            "normal" => Ok(Self::Normal),
37            "high" => Ok(Self::High),
38            _ => Err(format!("Unknown RequestPriority variant: {}", s)),
39        }
40    }
41}
42
43impl Default for RequestPriority {
44    fn default() -> Self {
45        Self::Low
46    }
47}