wip
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@@ -3,7 +3,7 @@ use nanobyte_tera::{hosts::static_filter, l18n::translate_filter, date::{calcula
|
||||
use ovlach_tera::entity::lang_entity;
|
||||
use rocket::{*, fairing::AdHoc};
|
||||
use rocket_dyn_templates::Template;
|
||||
use ::serde::Deserialize;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use tools::tera::advanced_filter;
|
||||
|
||||
pub mod routes;
|
||||
@@ -22,6 +22,13 @@ pub struct CVBackendConfig {
|
||||
cv_backend_path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct FrontendSVCConfig {
|
||||
pub contact_service: String,
|
||||
pub pdf_service: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct DefaultPerson {
|
||||
@@ -55,6 +62,8 @@ pub fn rocket_builder() -> Rocket<Build> {
|
||||
AdHoc::config::<CVBackendConfig>()
|
||||
).attach(
|
||||
AdHoc::config::<DefaultPerson>()
|
||||
).attach(
|
||||
AdHoc::config::<FrontendSVCConfig>()
|
||||
).attach(
|
||||
nanobyte_opentelemetry::rocket::TracingFairing::ignite()
|
||||
).mount("/", routes![
|
||||
|
||||
@@ -8,27 +8,29 @@ use rocket::{get, State, response::Redirect, http::Status, futures::executor::en
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBackendConfig, tools::rocket::RequestLanguage, DefaultPerson};
|
||||
use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBackendConfig, tools::rocket::RequestLanguage, DefaultPerson, FrontendSVCConfig};
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct RootPage {
|
||||
static_host: String,
|
||||
cv: CV,
|
||||
download_cv_url: String,
|
||||
lang: LanguageDescription,
|
||||
contact_svc: String,
|
||||
pdf_download_url: String
|
||||
}
|
||||
|
||||
#[get("/<language>")]
|
||||
pub async fn index(presentation_config: &State<PresentationConfig>, cv_config: &State<CVBackendConfig>, language: RequestLanguage, client: OtelReqwestClient,
|
||||
default_person: &State<DefaultPerson>, span: TracingSpan) -> Result<Template, Status> {
|
||||
default_person: &State<DefaultPerson>, frontend_svc: &State<FrontendSVCConfig>, span: TracingSpan) -> Result<Template, Status> {
|
||||
let span = span.0.enter();
|
||||
|
||||
let context = match fetch_cv_data_from_backend(&cv_config.cv_backend_path, &default_person.default_person_name, &client.0).await {
|
||||
Ok(cv) => RootPage {
|
||||
static_host: presentation_config.static_route.clone(),
|
||||
cv,
|
||||
download_cv_url: "FIXME!".to_string(),
|
||||
lang: LanguageDescription::new(&language.language.as_str(), "ovlach_frontend"),
|
||||
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)
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Can't fetch CV data from backend {:?}", e);
|
||||
|
||||
Reference in New Issue
Block a user