Skip to main content

backbone_activity/domain/entity/
activity_status.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 = "activity_status", rename_all = "snake_case")]
11pub enum ActivityStatus {
12    Planned,
13    InProgress,
14    Done,
15    Cancelled,
16}
17
18impl std::fmt::Display for ActivityStatus {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Planned => write!(f, "planned"),
22            Self::InProgress => write!(f, "in_progress"),
23            Self::Done => write!(f, "done"),
24            Self::Cancelled => write!(f, "cancelled"),
25        }
26    }
27}
28
29impl FromStr for ActivityStatus {
30    type Err = String;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_lowercase().as_str() {
34            "planned" => Ok(Self::Planned),
35            "in_progress" => Ok(Self::InProgress),
36            "done" => Ok(Self::Done),
37            "cancelled" => Ok(Self::Cancelled),
38            _ => Err(format!("Unknown ActivityStatus variant: {}", s)),
39        }
40    }
41}
42
43impl Default for ActivityStatus {
44    fn default() -> Self {
45        Self::Planned
46    }
47}