Skip to main content

ito_domain/tasks/
repository.rs

1//! Task repository port definitions.
2
3use super::parse::{ProgressInfo, TaskItem, TasksParseResult};
4use crate::errors::DomainResult;
5
6/// Port for accessing task data.
7///
8/// Domain and adapters should depend on this interface rather than concrete
9/// storage details.
10pub trait TaskRepository {
11    /// Load all tasks for a change.
12    ///
13    /// Returns the full parse result including diagnostics.
14    fn load_tasks(&self, change_id: &str) -> DomainResult<TasksParseResult>;
15
16    /// Get task progress for a change.
17    ///
18    /// This is a convenience method that returns just the progress info.
19    fn get_progress(&self, change_id: &str) -> DomainResult<ProgressInfo> {
20        let result = self.load_tasks(change_id)?;
21        Ok(result.progress)
22    }
23
24    /// Get task counts (completed, total) for a change.
25    ///
26    /// Implementations should return `(0, 0)` when the tasks file doesn't exist.
27    fn get_task_counts(&self, change_id: &str) -> DomainResult<(u32, u32)> {
28        let progress = self.get_progress(change_id)?;
29        Ok((progress.complete as u32, progress.total as u32))
30    }
31
32    /// Check if a change has any tasks defined.
33    fn has_tasks(&self, change_id: &str) -> DomainResult<bool> {
34        let progress = self.get_progress(change_id)?;
35        Ok(progress.total > 0)
36    }
37
38    /// Get all tasks for a change.
39    fn get_tasks(&self, change_id: &str) -> DomainResult<Vec<TaskItem>> {
40        let result = self.load_tasks(change_id)?;
41        Ok(result.tasks)
42    }
43}