taskman 0.1.0

Cli for the task management.
use crate::domain::{ CreateTaskRequest};
use crate::persister;

pub trait Execute {
    fn execute(&self);
}

#[derive(Debug)]
pub(crate) enum Command {
    CreateTask(CreateTask),
    GetTasks(GetTasks),
    DeleteTask(DeleteTask),
}

impl Command {
    pub(crate) fn execute(&self) {
        match self {
            Command::GetTasks(value) => value.execute(),
            Command::DeleteTask(value) => value.execute(),
            Command::CreateTask(value) => value.execute(),
        }
    }
}
#[derive(Debug)]
pub(crate) struct GetTasks {
    pub(crate) page_number: Option<usize>,
    pub(crate) page_size: Option<usize>,
}
impl GetTasks {
    pub(crate) fn from(page_number: Option<usize>, page_size: Option<usize>) -> GetTasks {
        GetTasks {
            page_number,
            page_size,
        }
    }
}
#[derive(Debug)]
pub(crate) struct CreateTask;

#[derive(Debug)]
pub(crate) struct DeleteTask{
  pub(crate) id: u64,
}

impl Execute for CreateTask {
    fn execute(&self) {
        let mut task_id = String::new();
        let mut task_name = String::new();
        let mut task_desc = String::new();
        println!("Please input the task id!");
        std::io::stdin().read_line(&mut task_id).unwrap();
        println!("Please input the task name!");
        std::io::stdin().read_line(&mut task_name).unwrap();
        println!("Please input the task description!");
        std::io::stdin().read_line(&mut task_desc).unwrap();
        let task = CreateTaskRequest {
            id: task_id.trim().parse().unwrap(),
            name: task_name.trim().to_string(),
            description: if !task_desc.is_empty() {
                Some(task_desc.trim().to_string())
            } else {
                None
            },
        };
        persister::save_task(&task);
    }
}

impl Execute for GetTasks {
    fn execute(&self) {
        let tasks = persister::get_tasks(self.page_number, self.page_size);
        //todo replace println on BufWriter
        tasks.iter().for_each(|task| println!("{task}"));
    }
}

impl Execute for DeleteTask {
    fn execute(&self) {
       persister::delete_task(self.id);
    }
}