ito_domain/tasks/
mutations.rs1use std::io;
4use std::path::PathBuf;
5
6use thiserror::Error;
7
8use super::parse::TaskItem;
9
10pub type TaskMutationServiceResult<T> = Result<T, TaskMutationError>;
12
13#[derive(Debug, Clone)]
15pub struct TaskMutationResult {
16 pub change_id: String,
18 pub task: TaskItem,
20 pub revision: Option<String>,
22}
23
24#[derive(Debug, Clone)]
26pub struct TaskInitResult {
27 pub change_id: String,
29 pub path: Option<PathBuf>,
31 pub existed: bool,
33 pub revision: Option<String>,
35}
36
37#[derive(Debug, Error)]
39pub enum TaskMutationError {
40 #[error("I/O failure while {context}: {source}")]
42 Io {
43 context: String,
45 #[source]
47 source: io::Error,
48 },
49
50 #[error("{0}")]
52 Validation(String),
53
54 #[error("{0}")]
56 NotFound(String),
57
58 #[error("{0}")]
60 Other(String),
61}
62
63impl TaskMutationError {
64 pub fn io(context: impl Into<String>, source: io::Error) -> Self {
66 Self::Io {
67 context: context.into(),
68 source,
69 }
70 }
71
72 pub fn validation(message: impl Into<String>) -> Self {
74 Self::Validation(message.into())
75 }
76
77 pub fn not_found(message: impl Into<String>) -> Self {
79 Self::NotFound(message.into())
80 }
81
82 pub fn other(message: impl Into<String>) -> Self {
84 Self::Other(message.into())
85 }
86}
87
88pub trait TaskMutationService: Send + Sync {
90 fn load_tasks_markdown(&self, change_id: &str) -> TaskMutationServiceResult<Option<String>>;
92 fn init_tasks(&self, change_id: &str) -> TaskMutationServiceResult<TaskInitResult>;
94 fn start_task(
96 &self,
97 change_id: &str,
98 task_id: &str,
99 ) -> TaskMutationServiceResult<TaskMutationResult>;
100 fn complete_task(
102 &self,
103 change_id: &str,
104 task_id: &str,
105 note: Option<String>,
106 ) -> TaskMutationServiceResult<TaskMutationResult>;
107 fn shelve_task(
109 &self,
110 change_id: &str,
111 task_id: &str,
112 reason: Option<String>,
113 ) -> TaskMutationServiceResult<TaskMutationResult>;
114 fn unshelve_task(
116 &self,
117 change_id: &str,
118 task_id: &str,
119 ) -> TaskMutationServiceResult<TaskMutationResult>;
120 fn add_task(
122 &self,
123 change_id: &str,
124 title: &str,
125 wave: Option<u32>,
126 ) -> TaskMutationServiceResult<TaskMutationResult>;
127}