use axum::{extract::State, response::Html, routing::post, Form, Router};
use tera::Context;
use crate::db::{Comment, NewComment};
pub fn app() -> axum::Router {
Router::new().route("/", post(post_comment))
}
async fn post_comment(
State(ctx): State,
Form(comment): Form,
) -> super::Result> {
let comment = tokio::task::spawn_blocking(move || comment.insert(&ctx.pool))
.await
.unwrap()?;
let mut context = Context::new();
context.insert("comment", &comment);
Ok(Html(ctx.tera.render("updates/comment_li.html", &context)?))
}