1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[deny(missing_docs)]
use serde::{Deserialize, Serialize};

/// A task represents a single job.
/// Usage example:
/// ```
/// use taskboard_core_lib::Task;
/// let task_1 = Task::new(1, "Learn rust");
/// let task_2 = Task::new(2, "Learn K8S");
/// assert_ne!(task_1, task_2);
/// ```
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Task {
    /// A number used for identifying tasks within a project
    pub number: usize,
    /// The task's title
    pub title: String,
    /// The task's current status
    pub status: Status,
    /// Remaning work in number of hours, or None if not specified
    pub remaining_work: Option<u8>,
}

/// A wrapper type with a list of tasks associated to a project
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ProjectTasks {
    /// Name of the related project
    pub project_name: String,
    /// All tasks associated with that project
    pub tasks: Vec<Task>,
}

#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
pub enum Status {
    Todo,
    Doing,
    Done,
}

impl Task {
    /// Creates a new Task with status Todo
    pub fn new(number: usize, title: &str) -> Self {
        Task {
            number,
            title: String::from(title),
            status: Status::Todo,
            remaining_work: None,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn new_should_set_status_to_todo() {
        assert_eq!(Task::new(1, "").status, Status::Todo);
    }

    #[test]
    fn new_should_not_set_remaining_work() {
        assert_eq!(Task::new(1, "").remaining_work, None);
    }
}