feat: also type update templates
parent
4e104d533c
commit
1b22c8d118
|
@ -1,7 +1,10 @@
|
||||||
use axum::{extract::State, response::Html, routing::post, Form, Router};
|
use axum::{extract::State, response::Html, routing::post, Form, Router};
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
|
||||||
use crate::db;
|
use crate::{
|
||||||
|
db,
|
||||||
|
template::{Template, Update},
|
||||||
|
};
|
||||||
|
|
||||||
pub fn app() -> axum::Router<crate::Context> {
|
pub fn app() -> axum::Router<crate::Context> {
|
||||||
Router::new().route("/", post(post_event))
|
Router::new().route("/", post(post_event))
|
||||||
|
@ -17,5 +20,5 @@ async fn post_event(
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("event", &event);
|
context.insert("event", &event);
|
||||||
Ok(Html(ctx.tera.render("updates/event_li.html", &context)?))
|
Ok(Html(Update::EventLi.render(&ctx.tera, &context)?))
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use tera::Context;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{self, DbError, Event, Pagination, Plant},
|
db::{self, DbError, Event, Pagination, Plant},
|
||||||
template::{Template, View},
|
template::{Template, Update, View},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{error::AppError, query::ToQuery};
|
use super::{error::AppError, query::ToQuery};
|
||||||
|
@ -90,5 +90,5 @@ async fn post_plant(
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("plant", &plant);
|
context.insert("plant", &plant);
|
||||||
Ok(Html(ctx.tera.render("updates/plant_li.html", &context)?))
|
Ok(Html(Update::PlantLi.render(&ctx.tera, &context)?))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
mod update;
|
||||||
mod view;
|
mod view;
|
||||||
|
|
||||||
|
pub use update::Update;
|
||||||
pub use view::View;
|
pub use view::View;
|
||||||
|
|
||||||
pub trait Template {
|
pub trait Template {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
use super::Template;
|
||||||
|
|
||||||
|
pub enum Update {
|
||||||
|
EventLi,
|
||||||
|
PlantLi,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Template for Update {
|
||||||
|
fn template(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Update::EventLi => "updates/event_li.html",
|
||||||
|
Update::PlantLi => "updates/plant_li.html",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue