1use serde::{Deserialize, Serialize};
2
3#[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 #[serde(default)]
12 pub references: Vec<String>,
13 pub updated_at: String,
14}
15
16#[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#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct TagCount {
29 pub name: String,
30 pub count: i64,
31}
32
33#[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#[derive(Debug, Clone)]
44pub struct CreateNote {
45 pub title: String,
46 pub body: String,
47 pub tags: Vec<String>,
48 pub references: Vec<String>,
50}
51
52#[derive(Debug, Default, Clone)]
54pub struct UpdateNote {
55 pub title: Option<String>,
56 pub body: Option<String>,
57 pub tags: Option<Vec<String>>,
58 pub references: Option<Vec<String>>,
60}
61
62impl Note {
63 pub fn to_summary(&self, max_len: usize) -> NoteSummary {
65 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 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}