feat: also type update templates

main
Jef Roosens 2025-01-26 13:23:11 +01:00
parent 4e104d533c
commit 1b22c8d118
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
4 changed files with 24 additions and 4 deletions

View File

@ -1,7 +1,10 @@
use axum::{extract::State, response::Html, routing::post, Form, Router};
use tera::Context;
use crate::db;
use crate::{
db,
template::{Template, Update},
};
pub fn app() -> axum::Router<crate::Context> {
Router::new().route("/", post(post_event))
@ -17,5 +20,5 @@ async fn post_event(
let mut context = Context::new();
context.insert("event", &event);
Ok(Html(ctx.tera.render("updates/event_li.html", &context)?))
Ok(Html(Update::EventLi.render(&ctx.tera, &context)?))
}

View File

@ -9,7 +9,7 @@ use tera::Context;
use crate::{
db::{self, DbError, Event, Pagination, Plant},
template::{Template, View},
template::{Template, Update, View},
};
use super::{error::AppError, query::ToQuery};
@ -90,5 +90,5 @@ async fn post_plant(
let mut context = Context::new();
context.insert("plant", &plant);
Ok(Html(ctx.tera.render("updates/plant_li.html", &context)?))
Ok(Html(Update::PlantLi.render(&ctx.tera, &context)?))
}

View File

@ -1,5 +1,7 @@
mod update;
mod view;
pub use update::Update;
pub use view::View;
pub trait Template {

View File

@ -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",
}
}
}