use canapi::Provider; use diesel::PgConnection; use rocket::http::uri::Origin; use rocket_contrib::Json; use serde_json; use serde_qs; use plume_api::posts::PostEndpoint; use plume_models::db_conn::DbConn; use plume_models::posts::Post; #[get("/posts/")] fn get(id: i32, conn: DbConn) -> Json { let post = >::get(&*conn, id).ok(); Json(json!(post)) } #[get("/posts")] fn list(conn: DbConn, uri: &Origin) -> Json { let query: PostEndpoint = serde_qs::from_str(uri.query().unwrap_or("")).expect("Invalid query string"); let post = >::list(&*conn, query); Json(json!(post)) }