Skip to content

Commit

Permalink
Merge pull request #30 from EdwinBetanc0urt/bugfix/load-document-by-c…
Browse files Browse the repository at this point in the history
…lient

fix: Load document by client.
  • Loading branch information
yamelsenih authored May 30, 2024
2 parents 90e5a35 + 246e007 commit 0a9e5e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
20 changes: 16 additions & 4 deletions src/models/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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}};
use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index};

use super::{client_index, user_index, role_index};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -317,8 +319,9 @@ 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);

// Find index
// Find index
match exists_index(_user_index.to_owned()).await {
Ok(_) => {
log::info!("Find with user index `{:}`", _user_index);
Expand All @@ -332,8 +335,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_role_index)
},
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
log::warn!("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::error!("No client index `{:}`", _client_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/models/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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}};
use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index};

use super::{client_index, user_index, role_index};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -285,6 +287,7 @@ 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);

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -300,8 +303,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_role_index)
},
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
log::warn!("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::error!("No client index `{:}`", _client_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/models/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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}};
use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index};

use super::{client_index, user_index, role_index};

#[derive(Deserialize, Extractible, Debug, Clone)]
#[salvo(extract(default_source(from = "body")))]
Expand Down Expand Up @@ -325,6 +327,7 @@ 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);

// Find index
match exists_index(_user_index.to_owned()).await {
Expand All @@ -340,8 +343,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>,
Ok(_role_index)
},
Err(error) => {
log::error!("No role index `{:}`", _role_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
log::warn!("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::error!("No client index `{:}`", _client_index);
return Err(Error::new(ErrorKind::InvalidData.into(), error))
}
}
}
}
}
Expand Down

0 comments on commit 0a9e5e1

Please sign in to comment.