2022-08-18 11:37:52 +03:00
|
|
|
//! Copyright (C) 2022, Dmitriy Pleshevskiy <dmitriy@ideascup.me>
|
|
|
|
//!
|
|
|
|
//! tas is free software: you can redistribute it and/or modify
|
|
|
|
//! it under the terms of the GNU General Public License as published by
|
|
|
|
//! the Free Software Foundation, either version 3 of the License, or
|
|
|
|
//! (at your option) any later version.
|
|
|
|
//!
|
|
|
|
//! tas is distributed in the hope that it will be useful,
|
|
|
|
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
//! GNU General Public License for more details.
|
|
|
|
//!
|
|
|
|
//! You should have received a copy of the GNU General Public License
|
|
|
|
//! along with tas. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
//!
|
2022-08-05 23:11:44 +03:00
|
|
|
pub mod fs;
|
2022-08-20 15:42:20 +03:00
|
|
|
pub mod sqlite;
|
2022-08-05 23:11:44 +03:00
|
|
|
|
2022-08-16 22:24:21 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-08-05 23:11:44 +03:00
|
|
|
use crate::domain;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2022-08-20 15:42:20 +03:00
|
|
|
Connect,
|
|
|
|
PrepareQuery,
|
|
|
|
QueryData,
|
2022-08-05 23:11:44 +03:00
|
|
|
NotFound,
|
|
|
|
InvalidData,
|
|
|
|
InsertData,
|
2022-08-20 15:42:20 +03:00
|
|
|
UpdateData,
|
|
|
|
RemoveData,
|
2022-08-05 23:11:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2022-08-20 15:42:20 +03:00
|
|
|
Error::Connect => f.write_str("Cannot connect to the repository"),
|
|
|
|
Error::PrepareQuery => f.write_str("Cannot prepare query"),
|
|
|
|
Error::QueryData => f.write_str("Cannot query data"),
|
2022-08-05 23:11:44 +03:00
|
|
|
Error::NotFound => f.write_str("Cannot find data"),
|
|
|
|
Error::InvalidData => f.write_str("Invalid data format"),
|
|
|
|
Error::InsertData => f.write_str("Cannot insert data"),
|
2022-08-20 15:42:20 +03:00
|
|
|
Error::UpdateData => f.write_str("Cannot update data"),
|
|
|
|
Error::RemoveData => f.write_str("Cannot remove data"),
|
2022-08-05 23:11:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for Error {}
|
|
|
|
|
|
|
|
pub struct InsertTaskData {
|
2022-08-16 15:43:44 +03:00
|
|
|
pub name: String,
|
2022-08-18 14:10:20 +03:00
|
|
|
pub project: Option<String>,
|
2022-08-16 22:24:21 +03:00
|
|
|
pub link: Option<String>,
|
2022-08-18 14:10:20 +03:00
|
|
|
pub dir_path: Option<PathBuf>,
|
2022-08-16 15:43:44 +03:00
|
|
|
pub index: Option<usize>,
|
2022-08-05 23:11:44 +03:00
|
|
|
}
|
|
|
|
|
2022-08-05 23:40:26 +03:00
|
|
|
pub struct UpdateTaskData {
|
2022-08-16 15:43:44 +03:00
|
|
|
pub name: Option<String>,
|
2022-08-18 14:10:20 +03:00
|
|
|
pub project: Option<Option<String>>,
|
2022-08-16 22:24:21 +03:00
|
|
|
pub link: Option<Option<String>>,
|
2022-08-18 14:10:20 +03:00
|
|
|
pub dir_path: Option<Option<PathBuf>>,
|
2022-08-05 23:40:26 +03:00
|
|
|
}
|
|
|
|
|
2022-08-05 23:11:44 +03:00
|
|
|
pub trait Repository {
|
2022-08-16 15:43:44 +03:00
|
|
|
fn get_current_task_opt(&self) -> Result<Option<domain::CurrentTaskInfo>, Error>;
|
|
|
|
|
2022-08-20 15:42:20 +03:00
|
|
|
fn get_task_opt(&self, id: domain::TaskIdx) -> Result<Option<domain::Task>, Error>;
|
2022-08-16 15:43:44 +03:00
|
|
|
|
2022-08-20 23:38:38 +03:00
|
|
|
fn get_tasks(&self, finished: bool) -> Result<Vec<domain::Task>, Error>;
|
2022-08-05 23:11:44 +03:00
|
|
|
|
2022-08-20 15:42:20 +03:00
|
|
|
fn remove_task(&self, id: domain::TaskIdx) -> Result<domain::Task, Error>;
|
2022-08-16 15:43:44 +03:00
|
|
|
|
2022-08-05 23:40:26 +03:00
|
|
|
fn update_task(
|
|
|
|
&self,
|
2022-08-20 15:42:20 +03:00
|
|
|
id: domain::TaskIdx,
|
2022-08-05 23:40:26 +03:00
|
|
|
update_data: UpdateTaskData,
|
|
|
|
) -> Result<domain::Task, Error>;
|
|
|
|
|
2022-08-05 23:11:44 +03:00
|
|
|
fn insert_task(&self, insert_data: InsertTaskData) -> Result<domain::Task, Error>;
|
2022-08-16 15:43:44 +03:00
|
|
|
|
2022-08-20 15:42:20 +03:00
|
|
|
fn start_task(&self, id: domain::TaskIdx) -> Result<domain::Task, Error>;
|
2022-08-16 15:43:44 +03:00
|
|
|
|
|
|
|
fn stop_task(&self) -> Result<domain::Task, Error>;
|
|
|
|
|
|
|
|
fn finish_task(&self) -> Result<domain::Task, Error>;
|
2022-08-05 23:11:44 +03:00
|
|
|
}
|