MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / edit

Function edit

examples/actix_example/api/src/lib.rs:93–120  ·  view source on GitHub ↗
(data: web::Data<AppState>, id: web::Path<i32>)

Source from the content-addressed store, hash-verified

91
92#[get(r#"/{id:\d+}"#)]
93async 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}")]
123async fn update(

Callers

nothing calls this directly

Calls 3

into_innerMethod · 0.80
newFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected