river_data_core/models/
annotations.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
14#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
15pub struct AnnotationUpsert {
16 pub source_key: String,
17 pub stream_id: Uuid,
18 pub time: DateTime<Utc>,
21 pub category: String,
22 pub text: String,
23 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub standard_curve_id: Option<Uuid>,
27}
28
29#[derive(Debug, Clone, Deserialize)]
31pub struct AnnotationMapping {
32 pub source_key: String,
33 pub id: Option<Uuid>,
35 pub status: String,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
48#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
49pub struct NoteUpsert {
50 pub source_key: String,
51 pub site_name: String,
52 pub text: String,
53 pub verified: bool,
54}
55
56#[derive(Debug, Clone, Deserialize)]
58pub struct NoteMapping {
59 pub source_key: String,
60 pub id: Option<Uuid>,
62 pub status: String,
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
72 fn annotation_upsert_round_trips() {
73 let up = AnnotationUpsert {
74 source_key: "corrections:12".into(),
75 stream_id: Uuid::nil(),
76 time: Utc::now(),
77 category: "audit".into(),
78 text: "corrected with the January curve".into(),
79 standard_curve_id: Some(Uuid::nil()),
80 };
81 let json = serde_json::to_value(&up).unwrap();
82 let back: AnnotationUpsert = serde_json::from_value(json).unwrap();
83 assert_eq!(back.source_key, up.source_key);
84 assert_eq!(back.standard_curve_id, up.standard_curve_id);
85 }
86
87 #[test]
88 fn an_annotation_without_a_curve_round_trips() {
89 let up = AnnotationUpsert {
90 source_key: "corrections:13".into(),
91 stream_id: Uuid::nil(),
92 time: Utc::now(),
93 category: "audit".into(),
94 text: "no curve".into(),
95 standard_curve_id: None,
96 };
97 let json = serde_json::to_value(&up).unwrap();
98 assert!(json.get("standard_curve_id").is_none());
99 let back: AnnotationUpsert = serde_json::from_value(json).unwrap();
100 assert!(back.standard_curve_id.is_none());
101 }
102
103 #[test]
104 fn note_upsert_round_trips() {
105 let up = NoteUpsert {
106 source_key: "notes:4".into(),
107 site_name: "FP1".into(),
108 text: "gauge replaced".into(),
109 verified: true,
110 };
111 let back: NoteUpsert = serde_json::from_value(serde_json::to_value(&up).unwrap()).unwrap();
112 assert_eq!(back.site_name, "FP1");
113 assert!(back.verified);
114 }
115}