memrec_common/types/
project.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5use super::config::MemoryConfig;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Project {
9 pub id: Uuid,
10 pub name: String,
11 pub description: Option<String>,
12 pub created_at: DateTime<Utc>,
13 pub config: ProjectConfig,
14}
15
16impl Project {
17 pub fn new(name: String) -> Self {
18 Self {
19 id: Uuid::new_v4(),
20 name,
21 description: None,
22 created_at: Utc::now(),
23 config: ProjectConfig::default(),
24 }
25 }
26
27 pub fn with_description(mut self, description: String) -> Self {
28 self.description = Some(description);
29 self
30 }
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[derive(Default)]
35pub struct ProjectConfig {
36 pub memory_config: MemoryConfig,
37 pub active: bool,
38}
39
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_project_creation() {
47 let project = Project::new("my-project".to_string());
48
49 assert!(!project.id.to_string().is_empty());
50 assert_eq!(project.name, "my-project");
51 assert!(project.description.is_none());
52 assert!(!project.config.active);
53 }
54
55 #[test]
56 fn test_project_with_description() {
57 let project = Project::new("test".to_string())
58 .with_description("Test project".to_string());
59
60 assert_eq!(project.description, Some("Test project".to_string()));
61 }
62
63 #[test]
64 fn test_project_serde() {
65 let project = Project::new("test".to_string());
66 let json = serde_json::to_string(&project).unwrap();
67 let parsed: Project = serde_json::from_str(&json).unwrap();
68
69 assert_eq!(project.id, parsed.id);
70 assert_eq!(project.name, parsed.name);
71 }
72}