tempo_cli/models/
workspace.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct Workspace {
7 pub id: Option<i64>,
8 pub name: String,
9 pub description: Option<String>,
10 pub path: Option<PathBuf>,
11 pub created_at: DateTime<Utc>,
12 pub updated_at: DateTime<Utc>,
13}
14
15impl Workspace {
16 pub fn new(name: String) -> Self {
17 let now = Utc::now();
18 Self {
19 id: None,
20 name,
21 description: None,
22 path: None,
23 created_at: now,
24 updated_at: now,
25 }
26 }
27
28 pub fn with_description(mut self, description: String) -> Self {
29 self.description = Some(description);
30 self
31 }
32
33 pub fn with_path(mut self, path: PathBuf) -> Self {
34 self.path = Some(path);
35 self
36 }
37
38 pub fn validate(&self) -> anyhow::Result<()> {
39 if self.name.is_empty() {
40 return Err(anyhow::anyhow!("Workspace name cannot be empty"));
41 }
42 Ok(())
43 }
44}