Get list of finished tasks #32

Merged
pleshevskiy merged 5 commits from finished into main 2022-08-21 00:02:18 +03:00
6 changed files with 58 additions and 19 deletions
Showing only changes of commit 8bd588070e - Show all commits

View file

@ -4,23 +4,58 @@ use xdg::BaseDirectories;
fn main() {
let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap();
let fs_repo = repo::fs::FsRepo::new(xdg_dirs.clone());
let sqlite_repo = repo::sqlite::SqliteRepo::new(xdg_dirs.clone()).unwrap();
log::info!("active tasks");
let fs_tasks = fs_repo.get_tasks(false).unwrap();
if !fs_tasks.is_empty() {
for task in fs_tasks {
log::info!("task: {}", task.name);
log::info!(" inserting...");
let sqlite_repo = repo::sqlite::SqliteRepo::new(xdg_dirs).unwrap();
for task in fs_tasks {
log::info!("task: {}", task.name);
log::info!(" inserting...");
sqlite_repo
.insert_task(repo::InsertTaskData {
name: task.name,
project: task.project,
link: task.link,
dir_path: task.dir_path,
index: None,
finished_at: None,
})
.unwrap();
sqlite_repo
.insert_task(repo::InsertTaskData {
name: task.name,
project: task.project,
link: task.link,
dir_path: task.dir_path,
index: None,
})
.unwrap();
log::info!(" inserted");
}
}
log::info!(" inserted");
log::info!("finished tasks");
let fs_tasks = fs_repo.get_tasks(true).unwrap();
if !fs_tasks.is_empty() {
let meta = std::fs::metadata(xdg_dirs.get_data_file(repo::fs::FINISHED_DATA_FILE)).unwrap();
let finished_at = meta
.modified()
.map(time::OffsetDateTime::from)
.unwrap_or_else(|_| time::OffsetDateTime::now_utc());
for task in fs_tasks {
log::info!("task: {}", task.name);
log::info!(" inserting...");
sqlite_repo
.insert_task(repo::InsertTaskData {
name: task.name,
project: task.project,
link: task.link,
dir_path: task.dir_path,
index: None,
finished_at: Some(finished_at),
})
// TODO: think of a better solution than idx
.ok();
log::info!(" inserted");
}
}
}

View file

@ -43,6 +43,7 @@ pub fn execute(repo: impl Repository, args: Args) {
.transpose()
.unwrap(),
index: None,
finished_at: None,
});
match res {

View file

@ -77,6 +77,7 @@ pub fn execute(repo: impl Repository, args: Args) {
project: target.project,
link: target.link,
dir_path: target.dir_path,
finished_at: None,
});
match res {
Ok(task) => {

View file

@ -55,6 +55,7 @@ pub struct InsertTaskData {
pub link: Option<String>,
pub dir_path: Option<PathBuf>,
pub index: Option<usize>,
pub finished_at: Option<time::OffsetDateTime>,
}
pub struct UpdateTaskData {

View file

@ -60,9 +60,9 @@ impl From<CurrentTaskInfo> for domain::CurrentTaskInfo {
}
}
const CURRENT_TASK_FILE: &str = "current.json";
const DATA_FILE: &str = "data.json";
const FINISHED_DATA_FILE: &str = "finished_data.json";
pub const CURRENT_TASK_FILE: &str = "current.json";
pub const DATA_FILE: &str = "data.json";
pub const FINISHED_DATA_FILE: &str = "finished_data.json";
pub struct FsRepo {
xdg_dirs: BaseDirectories,

View file

@ -121,8 +121,8 @@ impl Repository for SqliteRepo {
let mut stmt = self
.conn
.prepare(
"INSERT INTO tasks (name, project, link, dir_path)
VALUES (?1, ?2, ?3, ?4)",
"INSERT INTO tasks (name, project, link, dir_path, created_at, finished_at)
VALUES (?1, ?2, ?3, ?4, ?5, ?5)",
)
.map_err(|_| Error::PrepareQuery)?;
@ -134,6 +134,7 @@ impl Repository for SqliteRepo {
&insert_data
.dir_path
.and_then(|p| p.into_os_string().into_string().ok()),
&insert_data.finished_at,
))
.map_err(|_| Error::InsertData)?;