(data: web::Data<AppState>, id: web::Path<i32>)
| 91 | |
| 92 | #[get(r#"/{id:\d+}"#)] |
| 93 | async fn edit(data: web::Data<AppState>, id: web::Path<i32>) -> Result<HttpResponse, Error> { |
| 94 | let conn = &data.conn; |
| 95 | let template = &data.templates; |
| 96 | let id = id.into_inner(); |
| 97 | |
| 98 | let post: Option<post::Model> = Query::find_post_by_id(conn, id) |
| 99 | .await |
| 100 | .expect("could not find post"); |
| 101 | |
| 102 | let mut ctx = tera::Context::new(); |
| 103 | let body = match post { |
| 104 | Some(post) => { |
| 105 | ctx.insert("post", &post); |
| 106 | |
| 107 | template |
| 108 | .render("edit.html.tera", &ctx) |
| 109 | .map_err(|_| error::ErrorInternalServerError("Template error")) |
| 110 | } |
| 111 | None => { |
| 112 | ctx.insert("uri", &format!("/{}", id)); |
| 113 | |
| 114 | template |
| 115 | .render("error/404.html.tera", &ctx) |
| 116 | .map_err(|_| error::ErrorInternalServerError("Template error")) |
| 117 | } |
| 118 | }; |
| 119 | Ok(HttpResponse::Ok().content_type("text/html").body(body?)) |
| 120 | } |
| 121 | |
| 122 | #[post("/{id}")] |
| 123 | async fn update( |
nothing calls this directly
no test coverage detected