| 146 | } |
| 147 | |
| 148 | async fn edit_post( |
| 149 | state: State<AppState>, |
| 150 | Path(id): Path<i32>, |
| 151 | ) -> Result<Html<String>, (StatusCode, &'static str)> { |
| 152 | let post: post::Model = QueryCore::find_post_by_id(&state.conn, id) |
| 153 | .await |
| 154 | .expect("could not find post") |
| 155 | .unwrap_or_else(|| panic!("could not find post with id {id}")); |
| 156 | |
| 157 | let mut ctx = tera::Context::new(); |
| 158 | ctx.insert("post", &post); |
| 159 | |
| 160 | let body = state |
| 161 | .templates |
| 162 | .render("edit.html.tera", &ctx) |
| 163 | .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Template error"))?; |
| 164 | |
| 165 | Ok(Html(body)) |
| 166 | } |
| 167 | |
| 168 | async fn update_post( |
| 169 | state: State<AppState>, |