Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Index name with all values. #29

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions src/models/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use salvo::prelude::*;
use serde_json::json;
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}};
use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -317,9 +317,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,

let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id);
let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id);
let _client_index = client_index(_index.to_owned(), _language, _client_id);
let _language_index = language_index(_index.to_owned(), _language);
let _default_index = default_index(_index.to_owned());

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -328,33 +325,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_user_index)
},
Err(_) => {
log::info!("No user index `{:}`", _user_index);
log::warn!("No user index `{:}`", _user_index);
match exists_index(_role_index.to_owned()).await {
Ok(_) => {
log::info!("Find with role index `{:}`", _role_index);
Ok(_role_index)
},
Err(_) => {
log::info!("No role index `{:}`", _role_index);
match exists_index(_client_index.to_owned()).await {
Ok(_) => {
log::info!("Find with client index `{:}`", _client_index);
Ok(_client_index)
},
Err(_) => {
log::warn!("No client index `{:}`", _client_index);
match exists_index(_language_index.to_owned()).await {
Ok(_) => {
log::info!("Find with language index `{:}`", _language_index);
Ok(_language_index)
},
Err(_) => {
log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index);
Ok(_default_index)
}
}
}
}
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
Expand Down
19 changes: 4 additions & 15 deletions src/models/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use salvo::prelude::*;
use serde_json::json;
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{client_index, default_index, language_index}};
use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::client_index};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -167,27 +167,16 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
let _index: String = "form".to_string();

let _client_index = client_index(_index.to_owned(), _language, _client_id);
let _language_index = language_index(_index.to_owned(), _language);
let _default_index = default_index(_index.to_owned());

// Find index
match exists_index(_client_index.to_owned()).await {
Ok(_) => {
log::info!("Find with client index `{:}`", _client_index);
Ok(_client_index)
},
Err(_) => {
log::warn!("No client index `{:}`", _client_index);
match exists_index(_language_index.to_owned()).await {
Ok(_) => {
log::info!("Find with language index `{:}`", _language_index);
Ok(_language_index)
},
Err(_) => {
log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index);
Ok(_default_index)
}
}
Err(error) => {
log::error!("No client index `{:}`", _client_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
Expand Down
31 changes: 5 additions & 26 deletions src/models/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use salvo::prelude::*;
use serde_json::json;
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, client_index, language_index, default_index}};
use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -242,9 +242,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,

let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id);
let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id);
let _client_index = client_index(_index.to_owned(), _language, _client_id);
let _language_index = language_index(_index.to_owned(), _language);
let _default_index = default_index(_index.to_owned());

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -253,33 +250,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_user_index)
},
Err(_) => {
log::info!("No user index `{:}`", _user_index);
log::warn!("No user index `{:}`", _user_index);
match exists_index(_role_index.to_owned()).await {
Ok(_) => {
log::info!("Find with role index `{:}`", _role_index);
Ok(_role_index)
},
Err(_) => {
log::info!("No role index `{:}`", _role_index);
match exists_index(_client_index.to_owned()).await {
Ok(_) => {
log::info!("Find with client index `{:}`", _client_index);
Ok(_client_index)
},
Err(_) => {
log::info!("No client index `{:}`", _client_index);
match exists_index(_language_index.to_owned()).await {
Ok(_) => {
log::info!("Find with language index `{:}`", _language_index);
Ok(_language_index)
},
Err(_) => {
log::info!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index);
Ok(_default_index)
}
}
}
}
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ fn default_index(_index_name: String) -> String {
fn language_index(_index_name: String, _language: Option<&String>) -> String {
let mut _index_to_find: String = default_index(_index_name);
if let Some(language) = _language {
if language != "en_US" {
_index_to_find.push_str("_");
_index_to_find.push_str(language);
}
_index_to_find.push_str("_");
_index_to_find.push_str(language);
}
_index_to_find.to_lowercase()
}
Expand All @@ -37,7 +35,7 @@ fn client_index(_index_name: String, _language: Option<&String>, _client_id: Opt
let mut _index_to_find: String = language_index(_index_name, _language);
if let Some(client_id) = _client_id {
if let Ok(id) = client_id.parse::<i32>() {
if id > 0 {
if id >= 0 {
_index_to_find.push_str("_");
_index_to_find.push_str(client_id);
}
Expand All @@ -50,7 +48,7 @@ fn role_index(_index_name: String, _language: Option<&String>, _client_id: Optio
let mut _index_to_find: String = client_index(_index_name, _language, _client_id);
if let Some(role_id) = _role_id {
if let Ok(id) = role_id.parse::<i32>() {
if id > 0 {
if id >= 0 {
_index_to_find.push_str("_");
_index_to_find.push_str(role_id);
}
Expand All @@ -63,7 +61,7 @@ fn user_index(_index_name: String, _language: Option<&String>, _client_id: Optio
let mut _index_to_find: String = role_index(_index_name, _language, _client_id, _role_id);
if let Some(user_id) = _user_id {
if let Ok(id) = user_id.parse::<i32>() {
if id > 0 {
if id >= 0 {
_index_to_find.push_str("_");
_index_to_find.push_str(user_id);
}
Expand Down
31 changes: 5 additions & 26 deletions src/models/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use salvo::prelude::*;
use serde_json::json;
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}};
use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -285,9 +285,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,

let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id);
let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id);
let _client_index = client_index(_index.to_owned(), _language, _client_id);
let _language_index = language_index(_index.to_owned(), _language);
let _default_index = default_index(_index.to_owned());

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -296,33 +293,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_user_index)
},
Err(_) => {
log::info!("No user index `{:}`", _user_index);
log::warn!("No user index `{:}`", _user_index);
match exists_index(_role_index.to_owned()).await {
Ok(_) => {
log::info!("Find with role index `{:}`", _role_index);
Ok(_role_index)
},
Err(_) => {
log::info!("No role index `{:}`", _role_index);
match exists_index(_client_index.to_owned()).await {
Ok(_) => {
log::info!("Find with client index `{:}`", _client_index);
Ok(_client_index)
},
Err(_) => {
log::warn!("No client index `{:}`", _client_index);
match exists_index(_language_index.to_owned()).await {
Ok(_) => {
log::info!("Find with language index `{:}`", _language_index);
Ok(_language_index)
},
Err(_) => {
log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index);
Ok(_default_index)
}
}
}
}
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
Expand Down
31 changes: 5 additions & 26 deletions src/models/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use salvo::prelude::*;
use serde_json::json;
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}};
use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -325,9 +325,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,

let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id);
let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id);
let _client_index = client_index(_index.to_owned(), _language, _client_id);
let _language_index = language_index(_index.to_owned(), _language);
let _default_index = default_index(_index.to_owned());

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -336,33 +333,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_user_index)
},
Err(_) => {
log::info!("No user index `{:}`", _user_index);
log::warn!("No user index `{:}`", _user_index);
match exists_index(_role_index.to_owned()).await {
Ok(_) => {
log::info!("Find with role index `{:}`", _role_index);
Ok(_role_index)
},
Err(_) => {
log::info!("No role index `{:}`", _role_index);
match exists_index(_client_index.to_owned()).await {
Ok(_) => {
log::info!("Find with client index `{:}`", _client_index);
Ok(_client_index)
},
Err(_) => {
log::warn!("No client index `{:}`", _client_index);
match exists_index(_language_index.to_owned()).await {
Ok(_) => {
log::info!("Find with language index `{:}`", _language_index);
Ok(_language_index)
},
Err(_) => {
log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index);
Ok(_default_index)
}
}
}
}
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
Expand Down