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