mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
set name optional during index creation
This commit is contained in:
parent
0e12920910
commit
1b3312871e
@ -116,9 +116,8 @@ pub async fn get_index(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
struct IndexCreateRequest {
|
struct IndexCreateRequest {
|
||||||
name: String,
|
name: Option<String>,
|
||||||
uid: Option<String>,
|
uid: Option<String>,
|
||||||
// schema: Option<SchemaBody>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@ -138,6 +137,10 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||||||
.await
|
.await
|
||||||
.map_err(ResponseError::bad_request)?;
|
.map_err(ResponseError::bad_request)?;
|
||||||
|
|
||||||
|
if let (None, None) = (body.name.clone(), body.uid.clone()) {
|
||||||
|
return Err(ResponseError::bad_request("Index creation must have an uid"));
|
||||||
|
}
|
||||||
|
|
||||||
let db = &ctx.state().db;
|
let db = &ctx.state().db;
|
||||||
|
|
||||||
let uid = match body.uid {
|
let uid = match body.uid {
|
||||||
@ -157,14 +160,11 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||||||
|
|
||||||
let mut writer = db.main_write_txn().map_err(ResponseError::internal)?;
|
let mut writer = db.main_write_txn().map_err(ResponseError::internal)?;
|
||||||
|
|
||||||
created_index
|
let name = body.name.unwrap_or(uid.clone());
|
||||||
.main
|
|
||||||
.put_name(&mut writer, &body.name)
|
|
||||||
.map_err(ResponseError::internal)?;
|
|
||||||
|
|
||||||
// let schema: Option<Schema> = body.schema.clone().map(Into::into);
|
created_index.main
|
||||||
// let mut response_update_id = None;
|
.put_name(&mut writer, &name)
|
||||||
// if let Some(schema) = schema {
|
.map_err(ResponseError::internal)?;
|
||||||
|
|
||||||
writer.commit().map_err(ResponseError::internal)?;
|
writer.commit().map_err(ResponseError::internal)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user