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

Function list

examples/actix_example/api/src/lib.rs:38–62  ·  view source on GitHub ↗
(req: HttpRequest, data: web::Data<AppState>)

Source from the content-addressed store, hash-verified

36
37#[get("/")]
38async fn list(req: HttpRequest, data: web::Data<AppState>) -> Result<HttpResponse, Error> {
39 let template = &data.templates;
40 let conn = &data.conn;
41
42 // get params
43 let params = web::Query::<Params>::from_query(req.query_string()).unwrap();
44
45 let page = params.page.unwrap_or(1);
46 let posts_per_page = params.posts_per_page.unwrap_or(DEFAULT_POSTS_PER_PAGE);
47
48 let (posts, num_pages) = Query::find_posts_in_page(conn, page, posts_per_page)
49 .await
50 .expect("Cannot find posts in page");
51
52 let mut ctx = tera::Context::new();
53 ctx.insert("posts", &posts);
54 ctx.insert("page", &page);
55 ctx.insert("posts_per_page", &posts_per_page);
56 ctx.insert("num_pages", &num_pages);
57
58 let body = template
59 .render("index.html.tera", &ctx)
60 .map_err(|_| error::ErrorInternalServerError("Template error"))?;
61 Ok(HttpResponse::Ok().content_type("text/html").body(body))
62}
63
64#[get("/new")]
65async fn new(data: web::Data<AppState>) -> Result<HttpResponse, Error> {

Callers

nothing calls this directly

Calls 3

unwrapMethod · 0.80
newFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected