use super::{apply_effective_points, hierarchical, lock_board, open_board};
use crate::backlog::{BacklogItem, Status};
use crate::error::{Error, Result};
use crate::service::dod::read_common_dod;
use crate::sprint::Sprint;
use crate::storage::{BacklogItemRepository, SprintRepository};
use std::path::Path;
#[derive(Debug, Clone, PartialEq)]
pub struct BoardSnapshot {
pub items: Vec<BacklogItem>,
pub sprints: Vec<Sprint>,
pub config: serde_json::Value,
pub dod: Option<String>,
}
pub async fn export_snapshot(project_dir: &Path) -> Result<BoardSnapshot> {
let _lock = lock_board(project_dir).await?;
let (board_dir, repo, config) = open_board(project_dir).await?;
let (mut items, sprints, dod) = tokio::try_join!(
BacklogItemRepository::list(&repo),
SprintRepository::list(&repo),
read_common_dod(&board_dir),
)?;
apply_effective_points(
&mut items,
config.points.aggregate_children,
&Status::new(&config.done_column),
);
let items = hierarchical(items);
let config = serde_json::to_value(&config).map_err(|error| Error::Parse {
path: board_dir.join("config.toml"),
message: error.to_string(),
})?;
Ok(BoardSnapshot {
items,
sprints,
config,
dod,
})
}