diff --git a/api_routes/src/lib.rs b/api_routes/src/lib.rs index 48e3d34..a4a8438 100644 --- a/api_routes/src/lib.rs +++ b/api_routes/src/lib.rs @@ -37,16 +37,27 @@ impl Search { pub struct Introducer { pub list: &'static str, pub introduce: &'static str, + pub get_mini_index: &'static str, } impl Introducer { const fn new() -> Introducer { let list = "/api/v1/introducer/list"; let introduce = "/api/v1/introducer/new"; - Introducer { list, introduce } + let get_mini_index = "/api/v1/introducer/mini-index"; + Introducer { + list, + introduce, + get_mini_index, + } } } +#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)] +pub struct MiniIndex { + pub mini_index: String, +} + #[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)] pub struct Api { pub get_latest: &'static str, diff --git a/src/introduce.rs b/src/introduce.rs index acfb630..4f215f3 100644 --- a/src/introduce.rs +++ b/src/introduce.rs @@ -17,7 +17,7 @@ */ use std::collections::HashSet; -use actix_web::web; +use actix_web::web::{self, get}; use actix_web::{HttpResponse, Responder}; use actix_web_codegen_const_routes::get; use actix_web_codegen_const_routes::post; @@ -116,6 +116,15 @@ impl Ctx { } } +#[get(path = "ROUTES.introducer.get_mini_index")] +pub async fn get_mini_index(db: WebDB) -> ServiceResult { + let mini_index = db.export_mini_index().await?; + + let resp = MiniIndex { mini_index }; + + Ok(HttpResponse::Ok().json(resp)) +} + #[get(path = "ROUTES.introducer.list")] pub async fn list_introductions( db: WebDB, @@ -144,6 +153,7 @@ pub async fn new_introduction( pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(list_introductions); cfg.service(new_introduction); + cfg.service(get_mini_index); } #[cfg(test)] diff --git a/src/search.rs b/src/search.rs index 6a51cd2..cfa7be9 100644 --- a/src/search.rs +++ b/src/search.rs @@ -35,10 +35,8 @@ pub async fn search_repository( } else { format!("*{}*", payload.query) }; - println!("search query: {}", query); - let resp = db.search_repository(&query).await?; - println!("search_repository method: {:?}", resp); - Ok(HttpResponse::Ok().json(resp)) + let local_resp = db.search_repository(&query).await?; + Ok(HttpResponse::Ok().json(local_resp)) } pub fn services(cfg: &mut web::ServiceConfig) { @@ -130,6 +128,12 @@ mod tests { assert!(!search_res.is_empty()); assert_eq!(search_res.first().as_ref().unwrap().name, REPO_NAME); + let mini_index_resp = get_request!(&app, ROUTES.introducer.get_mini_index); + assert_eq!(mini_index_resp.status(), StatusCode::OK); + let mini_index: api_routes::MiniIndex = test::read_body_json(mini_index_resp).await; + assert!(!mini_index.mini_index.is_empty()); + assert!(mini_index.mini_index.contains(USERNAME)); + // test ends } }