Skip to main content

headless_lms_server/controllers/
mock_document_storage.rs

1use headless_lms_chatbot::citations::CourseMaterialDocument;
2
3use crate::prelude::*;
4
5const DOCUMENT_3: &str = r#"More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long. More content on the same mock course page. Another snippet. Long."#;
6
7// GET /api/v0/mock_document_storage/test/documents/{document_id}
8async fn mock_document_storage(
9    app_conf: web::Data<ApplicationConfiguration>,
10    document_id: web::Path<String>,
11) -> ControllerResult<String> {
12    assert!(app_conf.test_chatbot && app_conf.test_mode);
13    trace!("In mock document storage");
14
15    let base_url = app_conf.base_url.to_owned();
16
17    let res = match document_id.as_str() {
18        "document1" => serde_json::to_string(
19            &(CourseMaterialDocument {
20                chunk_id: "1".to_string(),
21                title: "Cited course page".to_string(),
22                url: format!("{base_url}/1"),
23                filepath: "document1".to_string(),
24                chunk: "Mock test page content\n This is test content blah".to_string(),
25            }),
26        ),
27        "document2" => serde_json::to_string(
28            &(CourseMaterialDocument {
29                chunk_id: "2".to_string(),
30                title: "Cited course page 2".to_string(),
31                url: format!("{base_url}/2"),
32                filepath: "document2".to_string(),
33                chunk: "Mock test page content 2\n This is another test page.".to_string(),
34            }),
35        ),
36        "document3" => serde_json::to_string(
37            &(CourseMaterialDocument {
38                chunk_id: "3".to_string(),
39                title: "Cited course page".to_string(),
40                url: format!("{base_url}/3"),
41                filepath: "document3".to_string(),
42                chunk: DOCUMENT_3.to_string(),
43            }),
44        ),
45        _ => Ok("{}".to_string()),
46    }?;
47
48    let token = skip_authorize();
49    token.authorized_ok(res)
50}
51
52pub fn _add_routes(cfg: &mut ServiceConfig) {
53    cfg.route(
54        "/test/documents/{document_id}",
55        web::get().to(mock_document_storage),
56    );
57}