rodo_lib 0.1.2

A Library for a Todo Manager
Documentation
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use uuid::Uuid;

use super::{assingee, comment, path, priority, recurring, state, tag, todo};
use crate::utils::{handler, Functions};

pub enum FIELDS {
    TODO(Functions<todo::Todo, todo::FIELDS>),
    STATE(Functions<state::State, state::FIELDS>),
    TAG(Functions<tag::Tag, tag::FIELDS>),
    RECURRING(Functions<recurring::Recurring, recurring::FIELDS>),
    PATH(Functions<path::Path, path::FIELDS>),
    ASSINGEE(Functions<assingee::Assingee, assingee::FIELDS>),
    PRIORITY(Functions<priority::Priority, priority::FIELDS>),
    COMMENT(Functions<comment::Comment, comment::FIELDS>),
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
/// Struct representing the JSON file
///
/// * `todos`: the list of todos
/// * `states`: the list of states
/// * `tags`: the list of tags
/// * `recurring`: the list of recurring todos
/// * `priorities`: the list of priorities
/// * `paths`: the list of paths
/// * `assingees`: the list of users
/// * `comments`: the list of comments
pub struct Rodo {
    todos: HashMap<Uuid, todo::Todo>,
    states: HashMap<Uuid, state::State>,
    tags: HashMap<Uuid, tag::Tag>,
    recurring: HashMap<Uuid, recurring::Recurring>,
    priorities: HashMap<Uuid, priority::Priority>,
    paths: HashMap<Uuid, path::Path>,
    assingees: HashMap<Uuid, assingee::Assingee>,
    comments: HashMap<Uuid, comment::Comment>,
}

impl Rodo {
    pub fn new() -> Self {
        Self {
            todos: HashMap::new(),
            states: HashMap::new(),
            tags: HashMap::new(),
            recurring: HashMap::new(),
            priorities: HashMap::new(),
            paths: HashMap::new(),
            assingees: HashMap::new(),
            comments: HashMap::new(),
        }
    }

    /// Parses the given Function and passes it to the corresponding Struct
    ///
    /// * `field`: the Table with its Function and Value
    pub fn parse(&mut self, field: FIELDS) {
        match field {
            FIELDS::TODO(f) => handler(&mut self.todos, f),
            FIELDS::STATE(f) => handler(&mut self.states, f),
            FIELDS::TAG(f) => handler(&mut self.tags, f),
            FIELDS::RECURRING(f) => handler(&mut self.recurring, f),
            FIELDS::PRIORITY(f) => handler(&mut self.priorities, f),
            FIELDS::PATH(f) => handler(&mut self.paths, f),
            FIELDS::ASSINGEE(f) => handler(&mut self.assingees, f),
            FIELDS::COMMENT(f) => handler(&mut self.comments, f),
        }
    }
}