nblm_core/models/responses/
source.rs1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::models::{NotebookSource, NotebookSourceId};
6
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct BatchCreateSourcesResponse {
10 #[serde(default)]
11 pub sources: Vec<NotebookSource>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub error_count: Option<i32>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, Default)]
17#[serde(rename_all = "camelCase")]
18pub struct UploadSourceFileResponse {
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub source_id: Option<NotebookSourceId>,
21 #[serde(flatten)]
22 pub extra: HashMap<String, serde_json::Value>,
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn batch_create_sources_response_deserializes_correctly() {
31 let json = r#"{
32 "sources": [
33 {
34 "name": "projects/123/locations/global/notebooks/abc/sources/123",
35 "title": "Test Source",
36 "metadata": {
37 "wordCount": 100
38 }
39 }
40 ],
41 "errorCount": 0
42 }"#;
43 let response: BatchCreateSourcesResponse = serde_json::from_str(json).unwrap();
44 assert_eq!(response.sources.len(), 1);
45 assert_eq!(response.error_count, Some(0));
46 assert_eq!(
47 response.sources[0].name,
48 "projects/123/locations/global/notebooks/abc/sources/123"
49 );
50 assert_eq!(response.sources[0].title.as_ref().unwrap(), "Test Source");
51 }
52
53 #[test]
54 fn upload_source_file_response_deserializes() {
55 let json = r#"{
56 "sourceId": {
57 "id": "projects/123/locations/global/notebooks/abc/sources/source-id"
58 },
59 "requestId": "abc123"
60 }"#;
61 let response: UploadSourceFileResponse = serde_json::from_str(json).unwrap();
62 assert_eq!(
63 response.source_id.as_ref().and_then(|id| id.id.as_deref()),
64 Some("projects/123/locations/global/notebooks/abc/sources/source-id")
65 );
66 assert_eq!(
67 response
68 .extra
69 .get("requestId")
70 .and_then(|value| value.as_str()),
71 Some("abc123")
72 );
73 }
74}