mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
rename update fields to camel case
This commit is contained in:
parent
a7bd0681a0
commit
588add8bec
@ -122,7 +122,7 @@ impl Data {
|
|||||||
Ok(self
|
Ok(self
|
||||||
.list_indexes()?
|
.list_indexes()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|i| i.name == name.as_ref()))
|
.find(|i| i.uid == name.as_ref()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_index(&self, name: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> {
|
pub fn create_index(&self, name: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> {
|
||||||
|
@ -70,7 +70,7 @@ impl IndexController for LocalIndexController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let meta = IndexMetadata {
|
let meta = IndexMetadata {
|
||||||
name: index_name,
|
uid: index_name,
|
||||||
uuid: meta.uuid.clone(),
|
uuid: meta.uuid.clone(),
|
||||||
created_at: meta.created_at,
|
created_at: meta.created_at,
|
||||||
updated_at: meta.created_at,
|
updated_at: meta.created_at,
|
||||||
@ -124,18 +124,18 @@ impl IndexController for LocalIndexController {
|
|||||||
fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
||||||
let metas = self.indexes.list_indexes()?;
|
let metas = self.indexes.list_indexes()?;
|
||||||
let mut output_meta = Vec::new();
|
let mut output_meta = Vec::new();
|
||||||
for (name, meta, primary_key) in metas {
|
for (uid, meta, primary_key) in metas {
|
||||||
let created_at = meta.created_at;
|
let created_at = meta.created_at;
|
||||||
let uuid = meta.uuid;
|
let uuid = meta.uuid;
|
||||||
let updated_at = self
|
let updated_at = self
|
||||||
.all_update_status(&name)?
|
.all_update_status(&uid)?
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|u| u.processed().map(|u| u.processed_at))
|
.filter_map(|u| u.processed().map(|u| u.processed_at))
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(created_at);
|
.unwrap_or(created_at);
|
||||||
|
|
||||||
let index_meta = IndexMetadata {
|
let index_meta = IndexMetadata {
|
||||||
name,
|
uid,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
uuid,
|
uuid,
|
||||||
@ -146,7 +146,7 @@ impl IndexController for LocalIndexController {
|
|||||||
Ok(output_meta)
|
Ok(output_meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_index(&self, name: impl AsRef<str>, index_settings: IndexSettings) -> anyhow::Result<IndexMetadata> {
|
fn update_index(&self, uid: impl AsRef<str>, index_settings: IndexSettings) -> anyhow::Result<IndexMetadata> {
|
||||||
if index_settings.name.is_some() {
|
if index_settings.name.is_some() {
|
||||||
bail!("can't udpate an index name.")
|
bail!("can't udpate an index name.")
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ impl IndexController for LocalIndexController {
|
|||||||
let (primary_key, meta) = match index_settings.primary_key {
|
let (primary_key, meta) = match index_settings.primary_key {
|
||||||
Some(ref primary_key) => {
|
Some(ref primary_key) => {
|
||||||
self.indexes
|
self.indexes
|
||||||
.update_index(&name, |index| {
|
.update_index(&uid, |index| {
|
||||||
let mut txn = index.write_txn()?;
|
let mut txn = index.write_txn()?;
|
||||||
if index.primary_key(&txn)?.is_some() {
|
if index.primary_key(&txn)?.is_some() {
|
||||||
bail!("primary key already exists.")
|
bail!("primary key already exists.")
|
||||||
@ -166,8 +166,8 @@ impl IndexController for LocalIndexController {
|
|||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
let (index, meta) = self.indexes
|
let (index, meta) = self.indexes
|
||||||
.index_with_meta(&name)?
|
.index_with_meta(&uid)?
|
||||||
.with_context(|| format!("index {:?} doesn't exist.", name.as_ref()))?;
|
.with_context(|| format!("index {:?} doesn't exist.", uid.as_ref()))?;
|
||||||
let primary_key = index
|
let primary_key = index
|
||||||
.primary_key(&index.read_txn()?)?
|
.primary_key(&index.read_txn()?)?
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
@ -176,7 +176,7 @@ impl IndexController for LocalIndexController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(IndexMetadata {
|
Ok(IndexMetadata {
|
||||||
name: name.as_ref().to_string(),
|
uid: uid.as_ref().to_string(),
|
||||||
uuid: meta.uuid.clone(),
|
uuid: meta.uuid.clone(),
|
||||||
created_at: meta.created_at,
|
created_at: meta.created_at,
|
||||||
updated_at: meta.updated_at,
|
updated_at: meta.updated_at,
|
||||||
|
@ -21,7 +21,7 @@ pub type UpdateStatus = updates::UpdateStatus<UpdateMeta, UpdateResult, String>;
|
|||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct IndexMetadata {
|
pub struct IndexMetadata {
|
||||||
pub name: String,
|
pub uid: String,
|
||||||
uuid: Uuid,
|
uuid: Uuid,
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
updated_at: DateTime<Utc>,
|
updated_at: DateTime<Utc>,
|
||||||
@ -223,8 +223,8 @@ pub(crate) mod test {
|
|||||||
|
|
||||||
let indexes = controller.list_indexes().unwrap();
|
let indexes = controller.list_indexes().unwrap();
|
||||||
assert_eq!(indexes.len(), 2);
|
assert_eq!(indexes.len(), 2);
|
||||||
assert_eq!(indexes[0].name, "test_index");
|
assert_eq!(indexes[0].uid, "test_index");
|
||||||
assert_eq!(indexes[1].name, "test_index2");
|
assert_eq!(indexes[1].uid, "test_index2");
|
||||||
assert_eq!(indexes[1].primary_key.clone().unwrap(), "foo");
|
assert_eq!(indexes[1].primary_key.clone().unwrap(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ pub(crate) mod test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = controller.update_index("test", settings).unwrap();
|
let result = controller.update_index("test", settings).unwrap();
|
||||||
assert_eq!(result.name, "test");
|
assert_eq!(result.uid, "test");
|
||||||
assert_eq!(result.created_at, result.updated_at);
|
assert_eq!(result.created_at, result.updated_at);
|
||||||
assert!(result.primary_key.is_none());
|
assert!(result.primary_key.is_none());
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ pub(crate) mod test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = controller.update_index("test", settings.clone()).unwrap();
|
let result = controller.update_index("test", settings.clone()).unwrap();
|
||||||
assert_eq!(result.name, "test");
|
assert_eq!(result.uid, "test");
|
||||||
assert!(result.created_at < result.updated_at);
|
assert!(result.created_at < result.updated_at);
|
||||||
assert_eq!(result.primary_key.unwrap(), "foo");
|
assert_eq!(result.primary_key.unwrap(), "foo");
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ use chrono::{Utc, DateTime};
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Pending<M> {
|
pub struct Pending<M> {
|
||||||
pub update_id: u64,
|
pub update_id: u64,
|
||||||
pub meta: M,
|
pub meta: M,
|
||||||
@ -115,7 +116,7 @@ impl<M, E> Failed<M, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Serialize)]
|
#[derive(Debug, PartialEq, Eq, Hash, Serialize)]
|
||||||
#[serde(tag = "status")]
|
#[serde(tag = "status", rename_all = "camelCase")]
|
||||||
pub enum UpdateStatus<M, N, E> {
|
pub enum UpdateStatus<M, N, E> {
|
||||||
Processing(Processing<M>),
|
Processing(Processing<M>),
|
||||||
Pending(Pending<M>),
|
Pending(Pending<M>),
|
||||||
|
@ -64,7 +64,6 @@ pub struct IndexerOpts {
|
|||||||
pub indexing_jobs: Option<usize>,
|
pub indexing_jobs: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl Default for IndexerOpts {
|
impl Default for IndexerOpts {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -52,7 +52,7 @@ async fn get_index(
|
|||||||
#[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,
|
uid: String,
|
||||||
primary_key: Option<String>,
|
primary_key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ async fn create_index(
|
|||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
body: web::Json<IndexCreateRequest>,
|
body: web::Json<IndexCreateRequest>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
match data.create_index(&body.name, body.primary_key.clone()) {
|
match data.create_index(&body.uid, body.primary_key.clone()) {
|
||||||
Ok(meta) => {
|
Ok(meta) => {
|
||||||
let json = serde_json::to_string(&meta).unwrap();
|
let json = serde_json::to_string(&meta).unwrap();
|
||||||
Ok(HttpResponse::Ok().body(json))
|
Ok(HttpResponse::Ok().body(json))
|
||||||
|
Loading…
Reference in New Issue
Block a user