| 83 | |
| 84 | #[handler] |
| 85 | async fn edit(req: &mut Request, depot: &mut Depot) -> Result<Text<String>> { |
| 86 | let state = depot |
| 87 | .obtain::<AppState>() |
| 88 | .ok_or_else(StatusError::internal_server_error)?; |
| 89 | let conn = &state.conn; |
| 90 | let id = req.param::<i32>("id").unwrap_or_default(); |
| 91 | |
| 92 | let post: post::Model = Query::find_post_by_id(conn, id) |
| 93 | .await |
| 94 | .map_err(|_| StatusError::internal_server_error())? |
| 95 | .ok_or_else(StatusError::not_found)?; |
| 96 | |
| 97 | let mut ctx = tera::Context::new(); |
| 98 | ctx.insert("post", &post); |
| 99 | |
| 100 | let body = state |
| 101 | .templates |
| 102 | .render("edit.html.tera", &ctx) |
| 103 | .map_err(|_| StatusError::internal_server_error())?; |
| 104 | Ok(Text::Html(body)) |
| 105 | } |
| 106 | |
| 107 | #[handler] |
| 108 | async fn update(req: &mut Request, depot: &mut Depot, res: &mut Response) -> Result<()> { |