2023-11-26 18:40:12 +01:00

32 lines
946 B
Rust

use log::error;
use ovlach_data::cv::cv::CV;
use rocket::{get, State, response::status::NotFound, http::Status};
use rocket_dyn_templates::{Template, context};
use serde::Serialize;
use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBackendConfig};
#[derive(Serialize, Debug)]
struct RootPage {
static_host: String,
cv: CV
}
#[get("/")]
pub async fn index(presentation_config: &State<PresentationConfig>, cv_config: &State<CVBackendConfig>) -> Result<Template, Status> {
let context = match fetch_cv_data_from_backend(cv_config.cv_backend_path.clone()).await {
Ok(cv) => RootPage {
static_host: presentation_config.static_route.clone(),
cv
},
Err(e) => {
error!("Can't fetch CV data from backend {:?}", e);
return Err(Status::InternalServerError)
}
};
//return Templ;
Ok(Template::render("default", &context))
}