Skip to main content

mnemo_core/model/
relation.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5pub struct Relation {
6    pub id: Uuid,
7    pub source_id: Uuid,
8    pub target_id: Uuid,
9    pub relation_type: String,
10    pub weight: f32,
11    pub metadata: serde_json::Value,
12    pub created_at: String,
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn test_relation_serde_roundtrip() {
21        let relation = Relation {
22            id: Uuid::now_v7(),
23            source_id: Uuid::now_v7(),
24            target_id: Uuid::now_v7(),
25            relation_type: "related_to".to_string(),
26            weight: 0.9,
27            metadata: serde_json::json!({}),
28            created_at: "2025-01-01T00:00:00Z".to_string(),
29        };
30        let json = serde_json::to_string(&relation).unwrap();
31        let deserialized: Relation = serde_json::from_str(&json).unwrap();
32        assert_eq!(relation, deserialized);
33    }
34}