| 76 | |
| 77 | #[handler] |
| 78 | async fn edit(state: Data<&AppState>, Path(id): Path<i32>) -> Result<impl IntoResponse> { |
| 79 | let conn = &state.conn; |
| 80 | |
| 81 | let post: post::Model = QueryCore::find_post_by_id(conn, id) |
| 82 | .await |
| 83 | .map_err(InternalServerError)? |
| 84 | .ok_or_else(|| Error::from_status(StatusCode::NOT_FOUND))?; |
| 85 | |
| 86 | let mut ctx = tera::Context::new(); |
| 87 | ctx.insert("post", &post); |
| 88 | |
| 89 | let body = state |
| 90 | .templates |
| 91 | .render("edit.html.tera", &ctx) |
| 92 | .map_err(InternalServerError)?; |
| 93 | Ok(Html(body)) |
| 94 | } |
| 95 | |
| 96 | #[handler] |
| 97 | async fn update( |