1use crate::namespace::Namespace;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub enum NoteStatus {
8 Open,
9 Resolved,
10 Approved,
11 Rejected,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct Note {
16 pub id: Uuid, pub commit: String, pub file: Option<String>, pub line_start: Option<u32>,
20 pub line_end: Option<u32>,
21 pub body: String, pub author: String, pub timestamp: DateTime<Utc>,
24 pub namespace: Namespace,
25 pub thread_id: Option<Uuid>, pub status: NoteStatus,
27 pub tags: Vec<String>,
28}
29
30impl Note {
31 #[allow(clippy::too_many_arguments)]
32 pub fn new(
33 commit: String,
34 file: Option<String>,
35 line_start: Option<u32>,
36 line_end: Option<u32>,
37 body: String,
38 author: String,
39 namespace: Namespace,
40 ) -> Self {
41 Self {
42 id: Uuid::new_v4(),
43 commit,
44 file,
45 line_start,
46 line_end,
47 body,
48 author,
49 timestamp: Utc::now(),
50 namespace,
51 thread_id: None,
52 status: NoteStatus::Open,
53 tags: Vec::new(),
54 }
55 }
56
57 pub fn reply(parent: &Note, body: String, author: String) -> Self {
58 Self {
59 id: Uuid::new_v4(),
60 commit: parent.commit.clone(),
61 file: parent.file.clone(),
62 line_start: parent.line_start,
63 line_end: parent.line_end,
64 body,
65 author,
66 timestamp: Utc::now(),
67 namespace: parent.namespace.clone(),
68 thread_id: Some(parent.id),
69 status: NoteStatus::Open,
70 tags: Vec::new(),
71 }
72 }
73}