From 08a10897bc13f556d78f3ca9c1257e31e081463d Mon Sep 17 00:00:00 2001 From: Tommaso Allevi Date: Fri, 31 Jan 2025 15:00:47 +0100 Subject: [PATCH 1/2] Move main APIs to v1 --- api-test.hurl | 7 ++++--- embedding-api-test.hurl | 6 +++--- src/collection_manager/dto.rs | 5 +---- src/collection_manager/sides/write/mod.rs | 4 ++-- src/tests.rs | 14 ++++---------- src/web_server/api/collection/admin.rs | 8 ++++---- src/web_server/api/collection/hooks.rs | 2 +- src/web_server/api/collection/search.rs | 2 +- 8 files changed, 20 insertions(+), 28 deletions(-) diff --git a/api-test.hurl b/api-test.hurl index 623b59f..4b4996b 100644 --- a/api-test.hurl +++ b/api-test.hurl @@ -9,7 +9,7 @@ HTTP 200 [Captures] collection_id: jsonpath "$[0]" -POST {{base_url}}/v0/collections +POST {{base_url}}/v1/collections/create Authorization: Bearer my-master-api-key { "id": "{{collection_id}}", @@ -23,7 +23,8 @@ HTTP 200 [Asserts] jsonpath "$.document_count" == 0 -PATCH {{base_url}}/v0/collections/{{collection_id}}/documents + +POST {{base_url}}/v1/collections/{{collection_id}}/insert Authorization: Bearer my-write-api-key [ { @@ -46,7 +47,7 @@ HTTP 200 [Asserts] jsonpath "$.document_count" == 2 -POST {{base_url}}/v0/collections/{{collection_id}}/search?api-key=my-read-api-key +POST {{base_url}}/v1/collections/{{collection_id}}/search?api-key=my-read-api-key [Options] retry: 10 retry-interval: 500ms diff --git a/embedding-api-test.hurl b/embedding-api-test.hurl index c3e220c..ef30eee 100644 --- a/embedding-api-test.hurl +++ b/embedding-api-test.hurl @@ -9,7 +9,7 @@ HTTP 200 [Captures] collection_id: jsonpath "$[0]" -POST {{base_url}}/v0/collections +POST {{base_url}}/v1/collections/create Authorization: Bearer my-master-api-key { "id": "{{collection_id}}", @@ -22,7 +22,7 @@ Authorization: Bearer my-master-api-key } HTTP 201 -PATCH {{base_url}}/v0/collections/{{collection_id}}/documents +POST {{base_url}}/v1/collections/{{collection_id}}/insert Authorization: Bearer my-write-api-key [ { @@ -41,7 +41,7 @@ Authorization: Bearer my-write-api-key HTTP 200 -POST {{base_url}}/v0/collections/{{collection_id}}/search?api-key=my-read-api-key +POST {{base_url}}/v1/collections/{{collection_id}}/search?api-key=my-read-api-key Authorization: Bearer my-read-api-key [Options] retry: 10 diff --git a/src/collection_manager/dto.rs b/src/collection_manager/dto.rs index ee66cf2..dce33ef 100644 --- a/src/collection_manager/dto.rs +++ b/src/collection_manager/dto.rs @@ -128,10 +128,7 @@ impl TryFrom for CreateCollection { } } -#[derive(Debug, Serialize, Deserialize, ToSchema)] -pub struct DeleteDocuments { - pub document_ids: Vec, -} +pub type DeleteDocuments = Vec; #[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)] pub struct CollectionDTO { diff --git a/src/collection_manager/sides/write/mod.rs b/src/collection_manager/sides/write/mod.rs index e8fc7c1..6b8a397 100644 --- a/src/collection_manager/sides/write/mod.rs +++ b/src/collection_manager/sides/write/mod.rs @@ -273,7 +273,7 @@ impl WriteSide { &self, write_api_key: ApiKey, collection_id: CollectionId, - delete_documents: DeleteDocuments, + document_ids_to_delete: DeleteDocuments, ) -> Result<()> { let collection = self .collections @@ -284,7 +284,7 @@ impl WriteSide { collection.check_write_api_key(write_api_key)?; collection - .delete_documents(delete_documents.document_ids, self.sender.clone()) + .delete_documents(document_ids_to_delete, self.sender.clone()) .await?; Ok(()) diff --git a/src/tests.rs b/src/tests.rs index 5da5e9d..2a273cd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -14,7 +14,7 @@ use crate::{ ai::AIServiceConfig, build_orama, collection_manager::{ - dto::{ApiKey, DeleteDocuments}, + dto::ApiKey, sides::{ CollectionsWriterConfig, IndexesConfig, OramaModelSerializable, ReadSide, WriteSide, }, @@ -1494,9 +1494,7 @@ async fn test_delete_documents() -> Result<()> { .delete_documents( ApiKey(Secret::new("my-write-api-key".to_string())), collection_id.clone(), - DeleteDocuments { - document_ids: vec![(document_count - 1).to_string()], - }, + vec![(document_count - 1).to_string()], ) .await?; sleep(Duration::from_millis(100)).await; @@ -1530,9 +1528,7 @@ async fn test_delete_documents() -> Result<()> { .delete_documents( ApiKey(Secret::new("my-write-api-key".to_string())), collection_id.clone(), - DeleteDocuments { - document_ids: vec![(document_count - 2).to_string()], - }, + vec![(document_count - 2).to_string()], ) .await?; sleep(Duration::from_millis(100)).await; @@ -1566,9 +1562,7 @@ async fn test_delete_documents() -> Result<()> { .delete_documents( ApiKey(Secret::new("my-write-api-key".to_string())), collection_id.clone(), - DeleteDocuments { - document_ids: vec![(document_count - 2).to_string()], - }, + vec![(document_count - 2).to_string()], ) .await?; sleep(Duration::from_millis(500)).await; diff --git a/src/web_server/api/collection/admin.rs b/src/web_server/api/collection/admin.rs index 27cca05..fba7728 100644 --- a/src/web_server/api/collection/admin.rs +++ b/src/web_server/api/collection/admin.rs @@ -88,7 +88,7 @@ type AuthorizationBearerHeader = #[endpoint( method = "POST", - path = "/v0/collections", + path = "/v1/collections/create", description = "Create a collection" )] async fn create_collection( @@ -118,8 +118,8 @@ async fn create_collection( } #[endpoint( - method = "PATCH", - path = "/v0/collections/{id}/documents", + method = "POST", + path = "/v1/collections/{id}/insert", description = "Add documents to a collection" )] async fn add_documents( @@ -157,7 +157,7 @@ async fn add_documents( #[endpoint( method = "POST", - path = "/v0/collections/{id}/delete-documents", + path = "/v1/collections/{id}/delete", description = "Delete documents from a collection" )] async fn delete_documents( diff --git a/src/web_server/api/collection/hooks.rs b/src/web_server/api/collection/hooks.rs index 59290a6..385d261 100644 --- a/src/web_server/api/collection/hooks.rs +++ b/src/web_server/api/collection/hooks.rs @@ -27,7 +27,7 @@ pub fn apis(write_side: Arc) -> Router { #[endpoint( method = "POST", - path = "/v0/{collection_id}/hooks/add", + path = "/v1/collections/{id}/hooks/create", description = "Add a new JavaScript hook" )] async fn add_hook_v0( diff --git a/src/web_server/api/collection/search.rs b/src/web_server/api/collection/search.rs index 945f7cb..a3192f2 100644 --- a/src/web_server/api/collection/search.rs +++ b/src/web_server/api/collection/search.rs @@ -51,7 +51,7 @@ struct SearchQueryParams { #[endpoint( method = "POST", - path = "/v0/collections/{id}/search", + path = "/v1/collections/{id}/search", description = "Search Endpoint" )] async fn search( From 178491013641a1c3f1062210094a1b0c2e21fd14 Mon Sep 17 00:00:00 2001 From: Tommaso Allevi Date: Fri, 31 Jan 2025 18:06:54 +0100 Subject: [PATCH 2/2] Move everything under v1 + auth (- exec action) --- api-test.hurl | 6 +- src/ai_server/src/actions/main.py | 2 +- src/collection_manager/sides/write/mod.rs | 88 +++++++++++++++++------ src/tests.rs | 16 +++-- src/web_server/api/collection/actions.rs | 2 +- src/web_server/api/collection/admin.rs | 68 ++++++++++-------- src/web_server/api/collection/answer.rs | 4 +- src/web_server/api/collection/hooks.rs | 81 +++++++++++++++++---- src/web_server/api/collection/search.rs | 30 +++----- 9 files changed, 204 insertions(+), 93 deletions(-) diff --git a/api-test.hurl b/api-test.hurl index 4b4996b..bca4b6c 100644 --- a/api-test.hurl +++ b/api-test.hurl @@ -18,7 +18,8 @@ Authorization: Bearer my-master-api-key } HTTP 201 -GET {{base_url}}/v0/collections/{{collection_id}} +GET {{base_url}}/v1/collections/{{collection_id}} +Authorization: Bearer my-master-api-key HTTP 200 [Asserts] jsonpath "$.document_count" == 0 @@ -42,7 +43,8 @@ Authorization: Bearer my-write-api-key ] HTTP 200 -GET {{base_url}}/v0/collections/{{collection_id}} +GET {{base_url}}/v1/collections/{{collection_id}} +Authorization: Bearer my-master-api-key HTTP 200 [Asserts] jsonpath "$.document_count" == 2 diff --git a/src/ai_server/src/actions/main.py b/src/ai_server/src/actions/main.py index a1567bd..3d26870 100644 --- a/src/ai_server/src/actions/main.py +++ b/src/ai_server/src/actions/main.py @@ -14,7 +14,7 @@ def __init__(self, config: OramaAIConfig): def call_oramacore_search(self, collection_id: str, query: Dict) -> any: body = json.dumps(query) - url = f"http://{self.config.rust_server_host}:{self.config.rust_server_port}/v0/{collection_id}/actions/execute" + url = f"http://{self.config.rust_server_host}:{self.config.rust_server_port}/v1/{collection_id}/actions/execute" headers = {"Content-Type": "application/json; charset=utf-8"} resp = requests.post(url=url, json={"context": body, "name": "search"}, headers=headers) diff --git a/src/collection_manager/sides/write/mod.rs b/src/collection_manager/sides/write/mod.rs index 49532fb..7772821 100644 --- a/src/collection_manager/sides/write/mod.rs +++ b/src/collection_manager/sides/write/mod.rs @@ -16,7 +16,7 @@ use std::{ use super::hooks::{HookName, HooksRuntime}; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use duration_str::deserialize_duration; use serde::{Deserialize, Serialize}; use tokio::{sync::RwLock, time::MissedTickBehavior}; @@ -208,9 +208,7 @@ impl WriteSide { master_api_key: ApiKey, option: CreateCollection, ) -> Result<()> { - if self.master_api_key != master_api_key { - return Err(anyhow::anyhow!("Invalid master api key")); - } + self.check_master_api_key(master_api_key)?; self.collections .create_collection(option, self.sender.clone(), self.hook_runtime.clone()) @@ -334,6 +332,7 @@ impl WriteSide { pub async fn insert_javascript_hook( &self, + write_api_key: ApiKey, collection_id: CollectionId, name: HookName, code: String, @@ -348,6 +347,8 @@ impl WriteSide { .await .ok_or_else(|| anyhow::anyhow!("Collection not found"))?; + collection.check_write_api_key(write_api_key)?; + collection .set_embedding_hook(name) .await @@ -356,39 +357,86 @@ impl WriteSide { Ok(()) } - pub async fn list_collections(&self) -> Vec { - self.collections.list().await + pub async fn list_collections(&self, master_api_key: ApiKey) -> Result> { + self.check_master_api_key(master_api_key)?; + + Ok(self.collections.list().await) } - pub async fn get_collection_dto(&self, collection_id: CollectionId) -> Option { - let collection = self.collections.get_collection(collection_id).await?; - Some(collection.as_dto().await) + pub async fn get_collection_dto( + &self, + master_api_key: ApiKey, + collection_id: CollectionId, + ) -> Result> { + self.check_master_api_key(master_api_key)?; + let collection = match self.collections.get_collection(collection_id).await { + Some(collection) => collection, + None => return Ok(None), + }; + Ok(Some(collection.as_dto().await)) } - pub fn get_javascript_hook( + pub async fn get_javascript_hook( &self, + write_api_key: ApiKey, collection_id: CollectionId, name: HookName, - ) -> Option { - self.hook_runtime + ) -> Result> { + let collection = self + .collections + .get_collection(collection_id.clone()) + .await + .ok_or_else(|| anyhow::anyhow!("Collection not found"))?; + collection.check_write_api_key(write_api_key)?; + + Ok(self + .hook_runtime .get_hook(collection_id, name) - .map(|hook| hook.code) + .map(|hook| hook.code)) } - pub fn delete_javascript_hook( + pub async fn delete_javascript_hook( &self, - _collection_id: CollectionId, + write_api_key: ApiKey, + collection_id: CollectionId, _name: HookName, - ) -> Option { - None // @todo: implement delete hook in HooksRuntime and CollectionsWriter + ) -> Result> { + let collection = self + .collections + .get_collection(collection_id) + .await + .ok_or_else(|| anyhow::anyhow!("Collection not found"))?; + collection.check_write_api_key(write_api_key)?; + + bail!("Not implemented yet.") // @todo: implement delete hook in HooksRuntime and CollectionsWriter } - pub fn list_javascript_hooks(&self, collection_id: CollectionId) -> HashMap { - self.hook_runtime + pub async fn list_javascript_hooks( + &self, + write_api_key: ApiKey, + collection_id: CollectionId, + ) -> Result> { + let collection = self + .collections + .get_collection(collection_id.clone()) + .await + .ok_or_else(|| anyhow::anyhow!("Collection not found"))?; + collection.check_write_api_key(write_api_key)?; + + Ok(self + .hook_runtime .list_hooks(collection_id) .into_iter() .map(|(name, hook)| (name, hook.code)) - .collect() + .collect()) + } + + fn check_master_api_key(&self, master_api_key: ApiKey) -> Result<()> { + if self.master_api_key != master_api_key { + return Err(anyhow::anyhow!("Invalid master api key")); + } + + Ok(()) } } diff --git a/src/tests.rs b/src/tests.rs index c6fff54..b2d27b7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -263,7 +263,9 @@ async fn test_commit_and_load() -> Result<()> { ) .await?; - let before_commit_collection_lists = write_side.list_collections().await; + let before_commit_collection_lists = write_side + .list_collections(ApiKey(Secret::new("my-master-api-key".to_string()))) + .await?; write_side.commit().await?; read_side.commit().await?; @@ -289,7 +291,9 @@ async fn test_commit_and_load() -> Result<()> { after_commit_result.hits[0].id ); - let after_commit_collection_lists = write_side.list_collections().await; + let after_commit_collection_lists = write_side + .list_collections(ApiKey(Secret::new("my-master-api-key".to_string()))) + .await?; assert_eq!( before_commit_collection_lists, @@ -311,7 +315,9 @@ async fn test_commit_and_load() -> Result<()> { assert_eq!(after_commit_result, after_load_result); - let after_load_collection_lists = write_side.list_collections().await; + let after_load_collection_lists = write_side + .list_collections(ApiKey(Secret::new("my-master-api-key".to_string()))) + .await?; assert_eq!(after_commit_collection_lists, after_load_collection_lists); @@ -356,7 +362,9 @@ async fn test_get_collections() -> Result<()> { create_collection(write_side.clone(), CollectionId(id.clone())).await?; } - let collections = write_side.list_collections().await; + let collections = write_side + .list_collections(ApiKey(Secret::new("my-master-api-key".to_string()))) + .await?; assert_eq!(collections.len(), 3); diff --git a/src/web_server/api/collection/actions.rs b/src/web_server/api/collection/actions.rs index 0de1216..b71037a 100644 --- a/src/web_server/api/collection/actions.rs +++ b/src/web_server/api/collection/actions.rs @@ -31,7 +31,7 @@ struct ActionQueryParams { #[endpoint( method = "POST", - path = "/v0/{collection_id}/actions/execute", + path = "/v1/{collection_id}/actions/execute", description = "Execute an action. Typically used by the Python server to perform actions that requires access to OramaCore components." )] #[axum::debug_handler] diff --git a/src/web_server/api/collection/admin.rs b/src/web_server/api/collection/admin.rs index fba7728..15dd275 100644 --- a/src/web_server/api/collection/admin.rs +++ b/src/web_server/api/collection/admin.rs @@ -27,65 +27,75 @@ pub fn apis(write_side: Arc) -> Router { .add(create_collection()) .add(add_documents()) .add(delete_documents()) - .add(dump_all()) .with_state(write_side) } +type AuthorizationBearerHeader = + TypedHeader>; + #[endpoint( - method = "POST", - path = "/v0/writer/dump_all", + method = "GET", + path = "/v1/collections", description = "List all collections" )] -async fn dump_all(write_side: State>) -> impl IntoResponse { - match write_side.commit().await { - Ok(_) => {} +async fn get_collections( + write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, +) -> Result>, (StatusCode, impl IntoResponse)> { + let master_api_key = ApiKey(Secret::new(auth.0.token().to_string())); + + let collections = match write_side.list_collections(master_api_key).await { + Ok(collections) => collections, Err(e) => { - error!("Error dumping all collections: {}", e); + error!("Error listing collections: {}", e); e.chain() .skip(1) .for_each(|cause| error!("because: {}", cause)); + return Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )); } - } - // writer.commit(data_dir) - - // Json(collections) - Json(()) -} - -#[endpoint( - method = "GET", - path = "/v0/collections", - description = "List all collections" -)] -async fn get_collections(write_side: State>) -> Json> { - let collections = write_side.list_collections().await; - Json(collections) + }; + Ok(Json(collections)) } #[endpoint( method = "GET", - path = "/v0/collections/{id}", + path = "/v1/collections/{id}", description = "Get a collection by id" )] async fn get_collection_by_id( Path(id): Path, write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, ) -> Result, (StatusCode, impl IntoResponse)> { + let master_api_key = ApiKey(Secret::new(auth.0.token().to_string())); + let collection_id = CollectionId(id); - let collection_dto = write_side.get_collection_dto(collection_id).await; + let collection_dto = write_side + .get_collection_dto(master_api_key, collection_id) + .await; match collection_dto { - Some(collection_dto) => Ok(Json(collection_dto)), - None => Err(( + Ok(Some(collection_dto)) => Ok(Json(collection_dto)), + Ok(None) => Err(( StatusCode::NOT_FOUND, Json(json!({ "error": "collection not found" })), )), + Err(e) => { + error!("Error get collection: {}", e); + e.chain() + .skip(1) + .for_each(|cause| error!("because: {}", cause)); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )) + } } } -type AuthorizationBearerHeader = - TypedHeader>; - #[endpoint( method = "POST", path = "/v1/collections/create", diff --git a/src/web_server/api/collection/answer.rs b/src/web_server/api/collection/answer.rs index c8b137c..03ff5c3 100644 --- a/src/web_server/api/collection/answer.rs +++ b/src/web_server/api/collection/answer.rs @@ -47,9 +47,9 @@ enum SseMessage { pub fn apis(read_side: Arc) -> Router { Router::new() - .route("/v0/collections/{id}/answer", post(answer_v0)) + .route("/v1/collections/{id}/answer", post(answer_v0)) .route( - "/v0/collections/{id}/planned_answer", + "/v1/collections/{id}/planned_answer", post(planned_answer_v0), ) .with_state(read_side) diff --git a/src/web_server/api/collection/hooks.rs b/src/web_server/api/collection/hooks.rs index 385d261..330b90d 100644 --- a/src/web_server/api/collection/hooks.rs +++ b/src/web_server/api/collection/hooks.rs @@ -5,17 +5,23 @@ use axum::{ response::IntoResponse, Json, Router, }; +use axum_extra::{headers, TypedHeader}; use axum_openapi3::*; use http::StatusCode; +use redact::Secret; use serde_json::json; use crate::{ collection_manager::{ - dto::DeleteHookParams, dto::GetHookQueryParams, dto::NewHookPostParams, sides::WriteSide, + dto::{ApiKey, DeleteHookParams, GetHookQueryParams, NewHookPostParams}, + sides::WriteSide, }, types::CollectionId, }; +type AuthorizationBearerHeader = + TypedHeader>; + pub fn apis(write_side: Arc) -> Router { Router::new() .add(add_hook_v0()) @@ -33,12 +39,15 @@ pub fn apis(write_side: Arc) -> Router { async fn add_hook_v0( Path(id): Path, write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, Json(params): Json, ) -> impl IntoResponse { let collection_id = CollectionId(id); + let write_api_key = ApiKey(Secret::new(auth.0.token().to_string())); + let NewHookPostParams { name, code } = params; match write_side - .insert_javascript_hook(collection_id, name, code) + .insert_javascript_hook(write_api_key, collection_id, name, code) .await { Ok(_) => Ok((StatusCode::OK, Json(json!({ "success": true })))), @@ -56,55 +65,99 @@ async fn add_hook_v0( #[endpoint( method = "GET", - path = "/v0/{collection_id}/hooks/get", + path = "/v1/{collection_id}/hooks/get", description = "Get an existing JavaScript hook" )] async fn get_hook_v0( Path(id): Path, write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, params: Query, -) -> impl IntoResponse { +) -> Result, (StatusCode, impl IntoResponse)> { let collection_id = CollectionId(id); + let write_api_key = ApiKey(Secret::new(auth.0.token().to_string())); + let GetHookQueryParams { name } = params.0; - match write_side.get_javascript_hook(collection_id, name) { - Some(full_hook) => Json(json!({ "hook": full_hook.to_string() })), - None => Json(json!({ "hook": null })), + match write_side + .get_javascript_hook(write_api_key, collection_id, name) + .await + { + Ok(Some(full_hook)) => Ok(Json(json!({ "hook": full_hook.to_string() }))), + Ok(None) => Ok(Json(json!({ "hook": null }))), + Err(e) => { + e.chain() + .skip(1) + .for_each(|cause| println!("because: {}", cause)); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )) + } } } #[endpoint( method = "DELETE", - path = "/v0/{collection_id}/hooks/remove", + path = "/v1/{collection_id}/hooks/remove", description = "Delete an existing JavaScript hook" )] async fn delete_hook_v0( Path(id): Path, write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, Json(params): Json, ) -> impl IntoResponse { let name = params.name; let collection_id = CollectionId(id); + let write_api_key = ApiKey(Secret::new(auth.0.token().to_string())); - match write_side.delete_javascript_hook(collection_id, name) { - Some(_) => Ok((StatusCode::OK, Json(json!({ "success": true })))), - None => Err(( + match write_side + .delete_javascript_hook(write_api_key, collection_id, name) + .await + { + Ok(Some(_)) => Ok((StatusCode::OK, Json(json!({ "success": true })))), + Ok(None) => Err(( StatusCode::UNPROCESSABLE_ENTITY, Json(json!({ "error": "Unable to find hook to delete" })), )), + Err(e) => { + e.chain() + .skip(1) + .for_each(|cause| println!("because: {}", cause)); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )) + } } } #[endpoint( method = "GET", - path = "/v0/{collection_id}/hooks/list", + path = "/v1/{collection_id}/hooks/list", description = "Get an existing JavaScript hook" )] async fn list_hooks_v0( Path(id): Path, write_side: State>, + TypedHeader(auth): AuthorizationBearerHeader, ) -> impl IntoResponse { let collection_id = CollectionId(id); - let hooks = write_side.list_javascript_hooks(collection_id); + let write_api_key = ApiKey(Secret::new(auth.0.token().to_string())); - Json(json!(hooks)) + match write_side + .list_javascript_hooks(write_api_key, collection_id) + .await + { + Ok(hooks) => Ok((StatusCode::OK, Json(json!(hooks)))), + Err(e) => { + e.chain() + .skip(1) + .for_each(|cause| println!("because: {}", cause)); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )) + } + } } diff --git a/src/web_server/api/collection/search.rs b/src/web_server/api/collection/search.rs index a3192f2..5d78609 100644 --- a/src/web_server/api/collection/search.rs +++ b/src/web_server/api/collection/search.rs @@ -23,26 +23,10 @@ use crate::{ pub fn apis(read_side: Arc) -> Router { Router::new() .add(search()) - .add(dump_all()) // .route("/:collection_id/documents/:document_id", get(get_doc_by_id)) .with_state(read_side) } -#[endpoint(method = "POST", path = "/v0/reader/dump_all", description = "Dump")] -async fn dump_all(read_side: State>) -> impl IntoResponse { - match read_side.commit().await { - Ok(_) => {} - Err(e) => { - error!("Error dumping all collections: {}", e); - e.chain() - .skip(1) - .for_each(|cause| error!("because: {}", cause)); - } - } - - axum::Json(()) -} - #[derive(Deserialize, IntoParams)] struct SearchQueryParams { #[serde(rename = "api-key")] @@ -67,10 +51,16 @@ async fn search( match output { Ok(data) => Ok((StatusCode::OK, Json(data))), - Err(e) => Err(( - StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({ "error": e.to_string() })), - )), + Err(e) => { + error!("Error deleting documents to collection: {}", e); + e.chain() + .skip(1) + .for_each(|cause| error!("because: {}", cause)); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ "error": e.to_string() })), + )) + } } }