diff --git a/index-scheduler/src/error.rs b/index-scheduler/src/error.rs index 61d61e2a1..af1decfe0 100644 --- a/index-scheduler/src/error.rs +++ b/index-scheduler/src/error.rs @@ -42,13 +42,15 @@ impl ErrorCode for Error { Error::IndexNotFound(_) => Code::IndexNotFound, Error::IndexAlreadyExists(_) => Code::IndexAlreadyExists, Error::TaskNotFound(_) => Code::TaskNotFound, - Error::InvalidStatus(_) => todo!(), - Error::InvalidKind(_) => todo!(), - Error::Heed(_) => todo!(), - Error::Milli(_) => todo!(), - Error::IndexError(_) => todo!(), - Error::FileStore(_) => todo!(), - Error::IoError(_) => todo!(), + Error::InvalidStatus(_) => Code::BadRequest, + Error::InvalidKind(_) => Code::BadRequest, + + // TODO: TAMO: are all these errors really internal? + Error::Heed(_) => Code::Internal, + Error::Milli(_) => Code::Internal, + Error::IndexError(_) => Code::Internal, + Error::FileStore(_) => Code::Internal, + Error::IoError(_) => Code::Internal, Error::Anyhow(_) => Code::Internal, Error::CorruptedTaskQueue => Code::Internal, } diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index 26b7a3c66..31f0c1858 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -260,19 +260,31 @@ async fn document_addition( } }; - let (file, uuid) = meilisearch.create_update_file()?; + // TODO: TAMO: do something with the update file + // Box::new(payload_to_stream(body)) + let (uuid, file) = meilisearch.create_update_file()?; - let update = KindWithContent::DocumentAddition { - content_file: Box::new(payload_to_stream(body)), - documents_count: 0, // TODO: TAMO: get the document count - primary_key, - method, - format, - allow_index_creation, - index_uid, + let task = match method { + IndexDocumentsMethod::ReplaceDocuments => KindWithContent::DocumentAddition { + content_file: uuid, + documents_count: 0, // TODO: TAMO: get the document count + primary_key, + allow_index_creation, + index_uid, + }, + + IndexDocumentsMethod::UpdateDocuments => KindWithContent::DocumentUpdate { + content_file: uuid, + documents_count: 0, // TODO: TAMO: get the document count + primary_key, + allow_index_creation, + index_uid, + }, + // TODO: TAMO: can I get rids of the `non_exhaustive` on the IndexDocumentsMethod enum + _ => todo!(), }; - let task = meilisearch.register_update(index_uid, update).await?.into(); + let task = meilisearch.register_task(task).await?; debug!("returns: {:?}", task); Ok(task) @@ -293,11 +305,11 @@ pub async fn delete_documents( }) .collect(); - let update = Update::DeleteDocuments(ids); - let task: SummarizedTaskView = meilisearch - .register_update(path.into_inner(), update) - .await? - .into(); + let task = KindWithContent::DocumentDeletion { + index_uid: path.into_inner(), + documents_ids: ids, + }; + let task = meilisearch.register_task(task).await?; debug!("returns: {:?}", task); Ok(HttpResponse::Accepted().json(task)) @@ -307,11 +319,10 @@ pub async fn clear_all_documents( meilisearch: GuardedData, MeiliSearch>, path: web::Path, ) -> Result { - let update = Update::ClearDocuments; - let task: SummarizedTaskView = meilisearch - .register_update(path.into_inner(), update) - .await? - .into(); + let task = KindWithContent::DocumentClear { + index_uid: path.into_inner(), + }; + let task = meilisearch.register_task(task).await?; debug!("returns: {:?}", task); Ok(HttpResponse::Accepted().json(task))