From b8ae41b2cebbec120f587946da06c9a3bd0ca97d Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Tue, 1 Oct 2024 12:34:27 -0400 Subject: [PATCH] feat: Add `type annotation`. --- src/bin/server.rs | 84 ++++++++++++++++++------------------ src/controller/opensearch.rs | 75 ++++++++++++++++---------------- src/models/browser.rs | 8 ++-- src/models/form.rs | 6 +-- src/models/generic.rs | 4 +- src/models/menu.rs | 4 +- src/models/menu_item.rs | 6 +-- src/models/menu_tree.rs | 4 +- src/models/process.rs | 6 +-- src/models/role.rs | 2 +- src/models/window.rs | 6 +-- 11 files changed, 103 insertions(+), 102 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 7a57691..88cdee0 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -185,7 +185,7 @@ async fn get_system_info<'a>(_req: &mut Request, _res: &mut Response) { }.to_owned() }; - let system_info_response = SystemInfoResponse { + let system_info_response: SystemInfoResponse = SystemInfoResponse { version: version.to_string(), is_kafka_enabled: kafka_enabled.trim().eq("Y"), kafka_queues: kafka_queues @@ -209,13 +209,13 @@ struct ErrorResponse { async fn get_forms<'a>(_req: &mut Request, _res: &mut Response) { let _id: Option = _req.param::("id"); let _language: Option<&String> = _req.queries().get("language"); - let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); - let _search_value = _req.queries().get("search_value"); + let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); + let _search_value: Option<&String> = _req.queries().get("search_value"); if _id.is_some() { match form_from_id(_id, _language, _dictionary_code).await { Ok(form) => _res.render(Json(form)), Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -232,7 +232,7 @@ async fn get_forms<'a>(_req: &mut Request, _res: &mut Response) { _res.render(Json(forms_list)); }, Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -247,14 +247,14 @@ async fn get_forms<'a>(_req: &mut Request, _res: &mut Response) { #[handler] async fn get_allowed_menu<'a>(_req: &mut Request, _res: &mut Response) { - let _language = _req.queries().get("language"); - let _client_id = _req.queries().get("client_id"); - let _role_id = _req.queries().get("role_id"); - let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); + let _language: Option<&String> = _req.queries().get("language"); + let _client_id: Option<&String> = _req.queries().get("client_id"); + let _role_id: Option<&String> = _req.queries().get("role_id"); + let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); match allowed_menu(_language, _client_id, _role_id, _dictionary_code).await { Ok(menu) => _res.render(Json(menu)), Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -268,15 +268,15 @@ async fn get_allowed_menu<'a>(_req: &mut Request, _res: &mut Response) { #[handler] async fn get_processes<'a>(_req: &mut Request, _res: &mut Response) { - let _id = _req.param::("id"); - let _language = _req.queries().get("language"); - let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); - let _search_value = _req.queries().get("search_value"); - if _id.is_some() { + let _id: Option = _req.param::("id"); + let _language: Option<&String> = _req.queries().get("language"); + let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); + let _search_value: Option<&String> = _req.queries().get("search_value"); + if _id.is_some() { match process_from_id(_id, _language, _dictionary_code).await { Ok(process) => _res.render(Json(process)), Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -307,15 +307,15 @@ async fn get_processes<'a>(_req: &mut Request, _res: &mut Response) { #[handler] async fn get_browsers<'a>(_req: &mut Request, _res: &mut Response) { - let _id = _req.param::("id"); - let _language = _req.queries().get("language"); - let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); - let _search_value = _req.queries().get("search_value"); - if _id.is_some() { + let _id: Option = _req.param::("id"); + let _language: Option<&String> = _req.queries().get("language"); + let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); + let _search_value: Option<&String> = _req.queries().get("search_value"); + if _id.is_some() { match browser_from_id(_id, _language, _dictionary_code).await { Ok(browser) => _res.render(Json(browser)), Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -331,7 +331,7 @@ async fn get_browsers<'a>(_req: &mut Request, _res: &mut Response) { _res.render(Json(browsers_list)); }, Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -346,15 +346,15 @@ async fn get_browsers<'a>(_req: &mut Request, _res: &mut Response) { #[handler] async fn get_windows<'a>(_req: &mut Request, _res: &mut Response) { - let _id: Option = _req.param::("id"); - let _language = _req.queries().get("language"); - let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); - let _search_value = _req.queries().get("search_value"); - if _id.is_some() { + let _id: Option = _req.param::("id"); + let _language: Option<&String> = _req.queries().get("language"); + let _dictionary_code: Option<&String> = _req.queries().get("dictionary_code"); + let _search_value: Option<&String> = _req.queries().get("search_value"); + if _id.is_some() { match window_from_id(_id, _language, _dictionary_code).await { Ok(window) => _res.render(Json(window)), Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -370,7 +370,7 @@ async fn get_windows<'a>(_req: &mut Request, _res: &mut Response) { _res.render(Json(windows_list)); }, Err(error) => { - let error_response = ErrorResponse { + let error_response: ErrorResponse = ErrorResponse { status: StatusCode::INTERNAL_SERVER_ERROR.into(), message: error.to_string() }; @@ -418,7 +418,7 @@ async fn consume_queue() { match consumer.recv().await { Err(e) => log::error!("Kafka error: {}", e), Ok(message) => { - let payload = match message.payload_view::() { + let payload: &str = match message.payload_view::() { None => "", Some(Ok(s)) => s, Some(Err(e)) => { @@ -426,7 +426,7 @@ async fn consume_queue() { "" } }; - let key = match message.key_view::() { + let key: &str = match message.key_view::() { None => "", Some(Ok(s)) => s, Some(Err(e)) => { @@ -434,10 +434,10 @@ async fn consume_queue() { "" } }; - let event_type = key.replace("\"", ""); - let topic = message.topic(); + let event_type: String = key.replace("\"", ""); + let topic: &str = message.topic(); if topic == "menu_item" { - let _document = match serde_json::from_str(payload) { + let _document: MenuItemDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -454,7 +454,7 @@ async fn consume_queue() { } } } else if topic == "menu_tree" { - let _document = match serde_json::from_str(payload) { + let _document: MenuTreeDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -471,7 +471,7 @@ async fn consume_queue() { } } } else if topic == "role" { - let _document = match serde_json::from_str(payload) { + let _document: RoleDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -488,7 +488,7 @@ async fn consume_queue() { } } } else if topic == "process" { - let _document = match serde_json::from_str(payload) { + let _document: ProcessDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -505,7 +505,7 @@ async fn consume_queue() { } } } else if topic == "browser" { - let _document = match serde_json::from_str(payload) { + let _document: BrowserDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -522,7 +522,7 @@ async fn consume_queue() { } } } else if topic == "window" { - let _document = match serde_json::from_str(payload) { + let _document: WindowDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -539,7 +539,7 @@ async fn consume_queue() { } } } else if topic == "form" { - let _document = match serde_json::from_str(payload) { + let _document: FormDocument = match serde_json::from_str(payload) { Ok(value) => value, Err(error) => { log::warn!("Topic: {:?}, {}", topic, error); @@ -593,4 +593,4 @@ async fn process_index(_event_type: String, _document: &dyn IndexDocument) -> Re }; } Ok(true) -} \ No newline at end of file +} diff --git a/src/controller/opensearch.rs b/src/controller/opensearch.rs index f0e92ef..b823016 100644 --- a/src/controller/opensearch.rs +++ b/src/controller/opensearch.rs @@ -1,8 +1,9 @@ use std::env; +use opensearch::http::response::Response; use opensearch::{OpenSearch, IndexParts, DeleteParts, SearchParts, GetParts}; use opensearch::http::Url; -use opensearch::http::transport::{SingleNodeConnectionPool, TransportBuilder}; +use opensearch::http::transport::{SingleNodeConnectionPool, Transport, TransportBuilder}; use opensearch::indices::{IndicesGetParts, IndicesCreateParts, IndicesDeleteParts}; use serde_json::Value; @@ -20,21 +21,21 @@ pub trait IndexDocument: Sync { } pub fn create_opensearch_client() -> Result { - let opensearch_url = match env::var("OPENSEARCH_URL") { + let opensearch_url: String = match env::var("OPENSEARCH_URL") { Ok(value) => value.clone(), Err(_) => { log::info!("Variable `OPENSEARCH_URL` Not found from enviroment, loaded with `default` value"); "http://localhost:9200".to_owned() }.to_owned(), }; - let url = match Url::parse(&opensearch_url) { + let url: Url = match Url::parse(&opensearch_url) { Ok(value) => value, Err(error) => { return Err(error.to_string()); }, }; - let conn_pool = SingleNodeConnectionPool::new(url); - let transport = match TransportBuilder::new(conn_pool) + let conn_pool: SingleNodeConnectionPool = SingleNodeConnectionPool::new(url); + let transport: Transport = match TransportBuilder::new(conn_pool) .disable_proxy() // .auth(Credentials::Basic("admin".to_owned(), "admin".to_owned())) .build() { @@ -47,7 +48,7 @@ pub fn create_opensearch_client() -> Result { } pub async fn exists_index(_index_name: String) -> Result { - let client = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); @@ -55,10 +56,10 @@ pub async fn exists_index(_index_name: String) -> Result { } }; // Get data - let _response = client.indices() + let _response: Result = client.indices() .get(IndicesGetParts::Index(&[&_index_name])) .send().await; - let response = match _response { + let response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -73,7 +74,7 @@ pub async fn exists_index(_index_name: String) -> Result { } pub async fn create_index_definition(_index: &dyn IndexDocument) -> Result { - let client = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); @@ -81,11 +82,11 @@ pub async fn create_index_definition(_index: &dyn IndexDocument) -> Result = client.indices() .get(IndicesGetParts::Index(&[&_index.index_name()])) .send().await; - let response = match _response { - Ok(value) => value, + let response: Response = match _response { + Ok(value) => value, Err(error) => { log::error!("{:?}", error); return Err(error.to_string()); @@ -93,7 +94,7 @@ pub async fn create_index_definition(_index: &dyn IndexDocument) -> Result = client .indices() .create(IndicesCreateParts::Index(&_index.index_name())) .body(_index.mapping()) @@ -118,7 +119,7 @@ pub async fn create_index_definition(_index: &dyn IndexDocument) -> Result Result { - let client = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); @@ -126,10 +127,10 @@ pub async fn delete_index_definition(_index: &dyn IndexDocument) -> Result = client.indices() .get(IndicesGetParts::Index(&[&_index.index_name()])) .send().await; - let response = match _response { + let response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -138,7 +139,7 @@ pub async fn delete_index_definition(_index: &dyn IndexDocument) -> Result = client .indices() .delete(IndicesDeleteParts::Index(&[&_index.index_name()])) .send() @@ -162,15 +163,15 @@ pub async fn delete_index_definition(_index: &dyn IndexDocument) -> Result Result { - let client: OpenSearch = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); return Err(error.to_string()); } }; - let _response = create_index_definition(_document).await; - let _response = match _response { + let _response: Result = create_index_definition(_document).await; + let _response: bool = match _response { Ok(_) => true, Err(error) => { log::error!("{:?}", error); @@ -187,11 +188,11 @@ pub async fn create(_document: &dyn IndexDocument) -> Result {}, }; // Create - let _response = client + let _response: Result = client .index(IndexParts::IndexId(&_document.index_name(), &_document.id())) .body(_document.data()) .send().await; - let _response = match _response { + let _response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -205,7 +206,7 @@ pub async fn create(_document: &dyn IndexDocument) -> Result Result { - let client = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); @@ -213,7 +214,7 @@ pub async fn delete(_document: &dyn IndexDocument) -> Result = client .delete(DeleteParts::IndexId(&_document.index_name(), &_document.id())) .send().await; match _response { @@ -243,7 +244,7 @@ pub async fn find(_document: &dyn IndexDocument, _search_value: String, _from: i .send() .await ; - let response = match _response { + let response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -253,16 +254,16 @@ pub async fn find(_document: &dyn IndexDocument, _search_value: String, _from: i if !response.status_code().is_success() { return Err(format!("Error finding record {:?}", response.text().await)); } - let response_body = match response.json::().await { + let response_body: Value = match response.json::().await { Ok(response) => response, Err(error) => { log::error!("{:?}", error); return Err(error.to_string()); }, }; - let mut list: Vec:: = Vec::new(); + let mut list: Vec:: = Vec::new(); for hit in response_body["hits"]["hits"].as_array().unwrap() { - let value = hit["_source"].to_owned(); + let value: Value = hit["_source"].to_owned(); list.push(value) } Ok(list) @@ -285,7 +286,7 @@ pub async fn find_from_dsl_body(_index_name: String, _body: serde_json::Value, _ .send() .await ; - let response = match _response { + let response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -295,23 +296,23 @@ pub async fn find_from_dsl_body(_index_name: String, _body: serde_json::Value, _ if !response.status_code().is_success() { return Err(format!("Error finding record {:?}", response.text().await)); } - let response_body = match response.json::().await { + let response_body: Value = match response.json::().await { Ok(response) => response, Err(error) => { log::error!("{:?}", error); return Err(error.to_string()); }, }; - let mut list: Vec:: = Vec::new(); + let mut list: Vec:: = Vec::new(); for hit in response_body["hits"]["hits"].as_array().unwrap() { - let value = hit["_source"].to_owned(); + let value: Value = hit["_source"].to_owned(); list.push(value) } Ok(list) } pub async fn get_by_id(_document: &dyn IndexDocument) -> Result { - let client = match create_opensearch_client() { + let client: OpenSearch = match create_opensearch_client() { Ok(client_value) => client_value, Err(error) => { log::error!("{:?}", error); @@ -319,10 +320,10 @@ pub async fn get_by_id(_document: &dyn IndexDocument) -> Result = client .get(GetParts::IndexId(&_document.index_name(), &_document.id())) .send().await; - let _response = match _response { + let _response: Response = match _response { Ok(value) => value, Err(error) => { log::error!("{:?}", error); @@ -332,7 +333,7 @@ pub async fn get_by_id(_document: &dyn IndexDocument) -> Result().await { + let response_body: Value = match _response.json::().await { Ok(response) => { response["_source"].to_owned() }, @@ -342,4 +343,4 @@ pub async fn get_by_id(_document: &dyn IndexDocument) -> Result) -> Self { - let mut browser = Browser::default(); + let mut browser: Browser = Browser::default(); browser.id = _id; browser } @@ -223,7 +223,7 @@ impl IndexDocument for Browser { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -323,7 +323,7 @@ pub async fn browser_from_id(_id: Option, _language: Option<&String>, _d } pub async fn browsers(_language: Option<&String>, _search_value: Option<&String>, _dictionary_code: Option<&String>) -> Result { - let _search_value = match _search_value { + let _search_value: String = match _search_value { Some(value) => value.clone(), None => "".to_owned() }; @@ -343,7 +343,7 @@ pub async fn browsers(_language: Option<&String>, _search_value: Option<&String> let _browser_document: &dyn IndexDocument = &_document; match find(_browser_document, _search_value, 0, 10).await { Ok(values) => { - let mut browsers_list: Vec = vec![]; + let mut browsers_list: Vec = vec![]; for value in values { let mut browser: Browser = serde_json::from_value(value).unwrap(); // sort fields by sequence diff --git a/src/models/form.rs b/src/models/form.rs index 8021312..ec6efc4 100644 --- a/src/models/form.rs +++ b/src/models/form.rs @@ -70,7 +70,7 @@ impl Default for Form { impl Form { pub fn from_id(_id: Option) -> Self { - let mut form = Form::default(); + let mut form: Form = Form::default(); form.id = _id; form } @@ -116,7 +116,7 @@ impl IndexDocument for Form { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -168,7 +168,7 @@ pub async fn form_from_id(_id: Option, _language: Option<&String>, _dict } pub async fn forms(_language: Option<&String>, _search_value: Option<&String>, _dictionary_code: Option<&String>) -> Result { - let _search_value = match _search_value { + let _search_value: String = match _search_value { Some(value) => value.clone(), None => "".to_owned() }; diff --git a/src/models/generic.rs b/src/models/generic.rs index 75f2057..927b032 100644 --- a/src/models/generic.rs +++ b/src/models/generic.rs @@ -64,7 +64,7 @@ impl IndexDocument for Generic { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -76,4 +76,4 @@ impl IndexDocument for Generic { } }) } -} \ No newline at end of file +} diff --git a/src/models/menu.rs b/src/models/menu.rs index 2e9041c..6b9d58e 100644 --- a/src/models/menu.rs +++ b/src/models/menu.rs @@ -95,13 +95,13 @@ impl Default for Menu { impl Menu { pub fn from_id(_id: Option) -> Self { - let mut menu = Menu::default(); + let mut menu: Menu = Menu::default(); menu.id = _id; menu } pub fn from_menu_item(_menu_item: MenuItem) -> Self { - let mut menu = Menu::default(); + let mut menu: Menu = Menu::default(); menu.uuid = _menu_item.uuid; menu.internal_id = _menu_item.internal_id; diff --git a/src/models/menu_item.rs b/src/models/menu_item.rs index 2e83960..24b51b0 100644 --- a/src/models/menu_item.rs +++ b/src/models/menu_item.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; use salvo::prelude::*; -use serde_json::json; +use serde_json::{json, Value}; use std::{io::ErrorKind, io::Error}; use crate::controller::opensearch::{find_from_dsl_body, IndexDocument}; @@ -306,7 +306,7 @@ impl IndexDocument for MenuItem { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -321,7 +321,7 @@ impl IndexDocument for MenuItem { } pub async fn menu_items_from_role(_role: Role, _language: Option<&String>, _dictionary_code: Option<&String>, _page_number: Option, _page_size: Option) -> Result, std::io::Error> { - let mut _search_body = MenuItem::get_find_body_from_role(_role); + let mut _search_body: Value = MenuItem::get_find_body_from_role(_role); let _index_name: String = match get_index_name("menu_item".to_string(), _language,_dictionary_code).await { Ok(index_name) => index_name, Err(error) => { diff --git a/src/models/menu_tree.rs b/src/models/menu_tree.rs index 91863bc..a982d11 100644 --- a/src/models/menu_tree.rs +++ b/src/models/menu_tree.rs @@ -70,7 +70,7 @@ impl Default for MenuTree { impl MenuTree { pub fn from_id(_id: Option) -> Self { - let mut menu = MenuTree::default(); + let mut menu: MenuTree = MenuTree::default(); menu.id = _id; menu } @@ -114,7 +114,7 @@ impl IndexDocument for MenuTree { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); diff --git a/src/models/process.rs b/src/models/process.rs index 13fe80c..3ab0511 100644 --- a/src/models/process.rs +++ b/src/models/process.rs @@ -172,7 +172,7 @@ impl Default for Process { impl Process { pub fn from_id(_id: Option) -> Self { - let mut process = Process::default(); + let mut process: Process = Process::default(); process.id = _id; process } @@ -219,7 +219,7 @@ impl IndexDocument for Process { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -304,7 +304,7 @@ pub async fn process_from_id(_id: Option, _language: Option<&String>, _d } pub async fn processes(_language: Option<&String>, _search_value: Option<&String>, _dictionary_code: Option<&String>) -> Result { - let _search_value = match _search_value { + let _search_value: String = match _search_value { Some(value) => value.clone(), None => "".to_owned() }; diff --git a/src/models/role.rs b/src/models/role.rs index 57e2203..4876e93 100644 --- a/src/models/role.rs +++ b/src/models/role.rs @@ -129,7 +129,7 @@ impl IndexDocument for Role { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); diff --git a/src/models/window.rs b/src/models/window.rs index 45e6a52..d163349 100644 --- a/src/models/window.rs +++ b/src/models/window.rs @@ -192,7 +192,7 @@ impl Default for Window { impl Window { pub fn from_id(_id: Option) -> Self { - let mut window = Window::default(); + let mut window: Window = Window::default(); window.id = _id; window } @@ -237,7 +237,7 @@ impl IndexDocument for Window { } fn find(self: &Self, _search_value: String) -> serde_json::Value { - let mut query = "*".to_owned(); + let mut query: String = "*".to_owned(); query.push_str(&_search_value.to_owned()); query.push_str(&"*".to_owned()); @@ -337,7 +337,7 @@ pub async fn window_from_id(_id: Option, _language: Option<&String>, _di } pub async fn windows(_language: Option<&String>, _search_value: Option<&String>, _dictionary_code: Option<&String>) -> Result { - let _search_value = match _search_value { + let _search_value: String = match _search_value { Some(value) => value.clone(), None => "".to_owned() };