MTP tools & Centralizing

This commit is contained in:
Alex Emmet 2026-06-30 22:52:08 +02:00
commit 3e6fcec171
9 changed files with 1549 additions and 291 deletions

View file

@ -4,7 +4,6 @@ use uuid::Uuid;
use crate::enums::{ToDoSource, ToDoStatus};
use crate::errors::ValidationError;
use crate::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use std::collections::HashSet;
const MAX_TITLE_LENGTH: usize = 500;
@ -132,8 +131,8 @@ impl ToDo {
false
}
/// Performs full graph cycle detection given a map of todo_id -> dependencies.
/// Returns the ID of the first todo that would participate in a cycle, or None.
/* DFS cycle detection over a full dependency graph. Returns the first
todo_id found in a cycle, or None when the graph is acyclic. */
pub fn detect_cycle_in_graph(deps: &std::collections::HashMap<Uuid, Vec<Uuid>>) -> Option<Uuid> {
let mut visited: HashSet<Uuid> = HashSet::new();
let mut in_stack: HashSet<Uuid> = HashSet::new();
@ -250,42 +249,6 @@ impl ToDo {
}
}
impl From<ToDo> for CommunicationValue {
fn from(todo: ToDo) -> Self {
let mut cv = CommunicationValue::new(CommunicationType::todo);
cv = cv.add_data(DataTypes::id, DataValue::Str(todo.id.to_string()));
cv = cv.add_data(DataTypes::title, DataValue::Str(todo.title));
cv = cv.add_data(DataTypes::description, DataValue::Str(todo.description));
cv = cv.add_data(DataTypes::status, DataValue::Str(todo.status.to_string()));
cv = cv.add_data(DataTypes::todo_id, DataValue::Number(todo.priority as i64));
let depends: Vec<DataValue> = todo
.depends_on
.iter()
.map(|u| DataValue::Str(u.to_string()))
.collect();
cv = cv.add_data(DataTypes::depends_on, DataValue::Array(depends));
cv = cv.add_data(
DataTypes::created_at,
DataValue::Str(todo.created_at.to_rfc3339()),
);
cv = cv.add_data(
DataTypes::updated_at,
DataValue::Str(todo.updated_at.to_rfc3339()),
);
cv = cv.add_data(
DataTypes::user_id,
DataValue::Str(todo.created_by.to_string()),
);
if let Some(pid) = todo.project_id {
cv = cv.add_data(DataTypes::project_id, DataValue::Str(pid.to_string()));
}
cv
}
}
#[cfg(test)]
mod tests {