Skip to main content

shipd_core/models/
task.rs

1use std::fmt;
2use std::str::FromStr;
3
4#[derive(Debug, Clone, PartialEq)]
5pub enum Status {
6    Todo,
7    InProgress,
8    Done,
9}
10
11impl fmt::Display for Status {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        let s = match self {
14            Status::Todo => "todo",
15            Status::InProgress => "in_progress",
16            Status::Done => "done",
17        };
18
19        write!(f, "{}", s)
20    }
21}
22
23impl FromStr for Status {
24    type Err = String;
25
26    fn from_str(s: &str) -> Result<Self, Self::Err> {
27        match s {
28            "todo" => Ok(Status::Todo),
29            "in_progress" => Ok(Status::InProgress),
30            "done" => Ok(Status::Done),
31            other => Err(format!("Invalid status: {other}")),
32        }
33    }
34}
35
36#[derive(Debug, Clone, PartialEq)]
37pub enum Priority {
38    Low,
39    Medium,
40    High,
41    Urgent,
42}
43
44impl fmt::Display for Priority {
45    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46        let s = match self {
47            Priority::Low => "low",
48            Priority::Medium => "medium",
49            Priority::High => "high",
50            Priority::Urgent => "urgent",
51        };
52
53        write!(f, "{}", s)
54    }
55}
56
57impl FromStr for Priority {
58    type Err = String;
59
60    fn from_str(s: &str) -> Result<Self, Self::Err> {
61        match s {
62            "low" => Ok(Priority::Low),
63            "medium" => Ok(Priority::Medium),
64            "high" => Ok(Priority::High),
65            "urgent" => Ok(Priority::Urgent),
66            other => Err(format!("Invalid priority: {other}")),
67        }
68    }
69}
70
71#[derive(Debug, Clone, PartialEq)]
72pub struct Task {
73    pub id: i64,
74    pub title: String,
75    pub description: Option<String>,
76    pub status: Status,
77    pub priority: Priority,
78    pub project_id: Option<i64>,
79    pub branch: Option<String>,
80    pub due_date: Option<String>,
81    pub created_at: String,
82    pub updated_at: String,
83}