handlers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::errors::{ Result }; use crate::forms::{ self }; use crate::state::{ ApplicationState }; use crate::templates; use axum::{ Form }; use axum::extract::{ Path, State }; use axum::http::{ StatusCode }; use axum::response::{ Html, IntoResponse, Redirect }; use std::sync::{ Arc }; pub(crate) async fn index_handler( State(state): State<Arc<ApplicationState>> ) -> Result<Html<String>> { let context = templates::index_context(&state)?; let html = state.tera.render("page.tera.html", &context)?; Ok(Html(html)) } pub(crate) async fn list_handler( State(state): State<Arc<ApplicationState>>, Path(list_path): Path<String> ) -> Result<Html<String>> { let context = templates::list_context(&state, &list_path)?; let html = state.tera.render("list.tera.html", &context)?; Ok(Html(html)) } pub(crate) async fn page_handler( State(state): State<Arc<ApplicationState>>, Path(page_path): Path<String> ) -> Result<Html<String>> { let context = templates::page_context(&state, &page_path)?; let html = state.tera.render("page.tera.html", &context)?; Ok(Html(html)) } pub(crate) async fn not_found_handler() -> impl IntoResponse { (StatusCode::NOT_FOUND, "Not found") } pub(crate) async fn contact_form_handler( State(state): State<Arc<ApplicationState>>, Form(contact): Form<forms::Contact> ) -> Result<Redirect> { contact.send_email(&state) .await?; Ok(Redirect::to("/page/message-sent")) }