Skip to main content

veta_core/
note.rs

1use serde::{Deserialize, Serialize};
2
3/// A full note with all fields.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Note {
6    pub id: i64,
7    pub title: String,
8    pub body: String,
9    pub tags: Vec<String>,
10    /// References to external resources (source code paths, URLs, documentation links, etc.)
11    #[serde(default)]
12    pub references: Vec<String>,
13    pub updated_at: String,
14}
15
16/// A summary of a note for listing (truncated body).
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct NoteSummary {
19    pub id: i64,
20    pub title: String,
21    pub body_preview: String,
22    pub tags: Vec<String>,
23    pub updated_at: String,
24}
25
26/// Tag with note count.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct TagCount {
29    pub name: String,
30    pub count: i64,
31}
32
33/// Query parameters for listing notes.
34#[derive(Debug, Default, Clone)]
35pub struct NoteQuery {
36    pub tags: Option<Vec<String>>,
37    pub from: Option<String>,
38    pub to: Option<String>,
39    pub limit: Option<i64>,
40}
41
42/// Parameters for creating a new note.
43#[derive(Debug, Clone)]
44pub struct CreateNote {
45    pub title: String,
46    pub body: String,
47    pub tags: Vec<String>,
48    /// References to external resources (source code paths, URLs, documentation links, etc.)
49    pub references: Vec<String>,
50}
51
52/// Parameters for updating an existing note.
53#[derive(Debug, Default, Clone)]
54pub struct UpdateNote {
55    pub title: Option<String>,
56    pub body: Option<String>,
57    pub tags: Option<Vec<String>>,
58    /// References to external resources (source code paths, URLs, documentation links, etc.)
59    pub references: Option<Vec<String>>,
60}
61
62impl Note {
63    /// Convert to summary with truncated first line of body.
64    pub fn to_summary(&self, max_len: usize) -> NoteSummary {
65        // Take only the first line
66        let first_line = self.body.lines().next().unwrap_or("");
67        let body_preview = if first_line.len() > max_len {
68            format!("{}...", &first_line[..max_len])
69        } else if first_line.len() < self.body.len() {
70            // There are more lines, indicate truncation
71            format!("{}...", first_line)
72        } else {
73            first_line.to_string()
74        };
75        NoteSummary {
76            id: self.id,
77            title: self.title.clone(),
78            body_preview,
79            tags: self.tags.clone(),
80            updated_at: self.updated_at.clone(),
81        }
82    }
83}