Skip to content
Clone
main
33 lines 1010 B Rust
use api::http::{HeaderMap, Html, Path, State};
use i18n::catalog;
use crate::errors::ApiError;
use crate::{AuthService, templates};
pub async fn agreement_page(
State(service): State<AuthService>,
headers: HeaderMap,
Path(key): Path<String>,
) -> Result<Html<String>, ApiError> {
let locale = service
.mail_locale(
None,
headers
.get(actix_web::http::header::ACCEPT_LANGUAGE)
.and_then(|value| value.to_str().ok()),
)
.await;
let doc = service.list_agreements().into_iter().find(|d| d.key == key);
match doc {
Some(doc) => {
let html_content = templates::render_markdown(&doc.content_md);
Ok(templates::page_agreement(&doc, &html_content, locale))
}
None => Ok(templates::page_message(
false,
catalog::agreement_not_found_title(locale),
catalog::agreement_not_found_body(locale),
locale,
)),
}
}