Skip to main content

ito_core/
backend_task_repository.rs

1//! Backend-backed task repository adapter.
2//!
3//! Delegates task reads to a [`BackendTaskReader`] when backend mode is
4//! enabled. Falls back to empty results when the backend has no tasks
5//! artifact for a change.
6
7use ito_domain::backend::BackendTaskReader;
8use ito_domain::errors::DomainResult;
9use ito_domain::tasks::{TaskRepository as DomainTaskRepository, TasksParseResult};
10
11/// Backend-backed task repository.
12///
13/// Wraps a [`BackendTaskReader`] and parses the tasks markdown content
14/// returned by the backend using the standard task parser.
15pub struct BackendTaskRepository<R: BackendTaskReader> {
16    reader: R,
17}
18
19impl<R: BackendTaskReader> BackendTaskRepository<R> {
20    /// Create a backend-backed task repository.
21    pub fn new(reader: R) -> Self {
22        Self { reader }
23    }
24}
25
26impl<R: BackendTaskReader> DomainTaskRepository for BackendTaskRepository<R> {
27    fn load_tasks(&self, change_id: &str) -> DomainResult<TasksParseResult> {
28        let content = self.reader.load_tasks_content(change_id)?;
29        let Some(content) = content else {
30            return Ok(TasksParseResult::empty());
31        };
32
33        Ok(ito_domain::tasks::parse_tasks_tracking_file(&content))
34    }
35}
36
37#[cfg(test)]
38#[path = "backend_task_repository_tests.rs"]
39mod backend_task_repository_tests;