This commit is contained in:
Ondrej Vlach 2023-12-03 17:41:04 +01:00
parent 32a9ed081e
commit 382e43b55f
Signed by: ovlach
GPG Key ID: 4FF1A23B4914DE70
5 changed files with 16 additions and 28 deletions

View File

@ -1,10 +1,8 @@
use std::{thread::sleep, time::Duration};
use log::error; use log::error;
use nanobyte_opentelemetry::rocket::{OtelReqwestClient, TracingSpan}; use nanobyte_opentelemetry::rocket::{OtelReqwestClient, TracingSpan};
use nanobyte_tera::l18n::LanguageDescription; use nanobyte_tera::l18n::LanguageDescription;
use ovlach_data::cv::data::CV; use ovlach_data::cv::data::CV;
use rocket::{get, State, response::Redirect, http::Status, futures::executor::enter}; use rocket::{get, State, response::Redirect, http::Status};
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
use serde::Serialize; use serde::Serialize;
@ -28,7 +26,7 @@ default_person: &State<DefaultPerson>, frontend_svc: &State<FrontendSVCConfig>,
Ok(cv) => RootPage { Ok(cv) => RootPage {
static_host: presentation_config.static_route.clone(), static_host: presentation_config.static_route.clone(),
cv, cv,
lang: LanguageDescription::new(&language.language.as_str(), "ovlach_frontend"), lang: LanguageDescription::new(language.language.as_str(), "ovlach_frontend"),
contact_svc: frontend_svc.inner().contact_service.clone(), contact_svc: frontend_svc.inner().contact_service.clone(),
pdf_download_url: format!("{}/cv/{}/output.pdf", frontend_svc.inner().pdf_service.clone(), default_person.default_person_name) pdf_download_url: format!("{}/cv/{}/output.pdf", frontend_svc.inner().pdf_service.clone(), default_person.default_person_name)
}, },
@ -39,7 +37,7 @@ default_person: &State<DefaultPerson>, frontend_svc: &State<FrontendSVCConfig>,
} }
}; };
let result = Ok(Template::render("default", &context)); let result = Ok(Template::render("default", context));
drop(span); drop(span);
result result
} }

View File

@ -1,3 +0,0 @@
pub fn get_lang_name_from_code(lang: &str) -> &str {
lang.split("-").collect::<Vec<&str>>()[0]
}

View File

@ -1,3 +1,2 @@
pub(crate) mod rocket; pub(crate) mod rocket;
pub(crate) mod lang;
pub(crate) mod tera; pub(crate) mod tera;

View File

@ -1,6 +1,4 @@
use std::time::SystemTime; use rocket::request::FromParam;
use log::info;
use rocket::{Request, Response, Data, fairing::{Kind, Info, Fairing}, request::{self, FromRequest, FromParam}, http::Status};
use phf::phf_map; use phf::phf_map;

View File

@ -39,21 +39,19 @@ pub fn advanced_filter(value: &Value, args: &HashMap<String, Value>) -> Result<V
"only" => true, "only" => true,
_ => false, _ => false,
} }
} else { } else if null != "only" {
if null != "only" { let val = tested_value.as_str();
let val = tested_value.as_str(); match val {
match val { Some(match_v) => {
Some(match_v) => { match against_value.clone() {
match against_value.clone() { Some(against_v) => match_v == against_v,
Some(against_v) => match_v == against_v, None => true,
None => true,
}
} }
None => true,
} }
} else { None => true,
false
} }
} else {
false
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -99,8 +97,6 @@ mod tests {
assert_eq!(result, json!(generate_test_class(Some("foo".to_string()), None))); assert_eq!(result, json!(generate_test_class(Some("foo".to_string()), None)));
let result = call_advanced_filter(&data, "none", None).unwrap(); let result = call_advanced_filter(&data, "none", None).unwrap();
assert_eq!(result, json!(vec![TestClass::new(Some("foo".to_string()))])); assert_eq!(result, json!(vec![TestClass::new(Some("foo".to_string()))]));
let mut vec: Vec<TestClass> = Vec::new();
vec.push(TestClass::new(None));
let result = call_advanced_filter(&data, "only", None).unwrap(); let result = call_advanced_filter(&data, "only", None).unwrap();
assert_eq!(result, json!(vec![TestClass::new(None)])); assert_eq!(result, json!(vec![TestClass::new(None)]));
@ -108,9 +104,9 @@ mod tests {
let result = call_advanced_filter(&data, "all", Some("foo")).unwrap(); let result = call_advanced_filter(&data, "all", Some("foo")).unwrap();
assert_eq!(result, json!(vec![TestClass::new(Some("foo".to_string())), TestClass::new(None)])); assert_eq!(result, json!(vec![TestClass::new(Some("foo".to_string())), TestClass::new(None)]));
let result = call_advanced_filter(&data, "none", Some("bar")).unwrap(); let result = call_advanced_filter(&data, "none", Some("bar")).unwrap();
let vec: Vec<TestClass> = Vec::new(); let vec: Vec<TestClass> = vec![];
assert_eq!(result, json!(vec)); assert_eq!(result, json!(vec));
let result = call_advanced_filter(&data, "only", Some("zz")).is_err(); let result = call_advanced_filter(&data, "only", Some("zz")).is_err();
assert_eq!(result, true); assert!(result);
} }
} }