Mount the API endpoints

This commit is contained in:
Bat
2018-09-25 20:45:32 +01:00
parent 472da486e9
commit f893056d6d
4 changed files with 22 additions and 3 deletions
+12 -2
View File
@@ -1,11 +1,21 @@
use canapi::Provider;
use diesel::PgConnection;
use rocket_contrib::Json;
use serde_json;
use plume_api::posts::PostEndpoint;
use plume_models::db_conn::DbConn;
use plume_models::posts::Post;
#[get("/posts/<id>")]
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
let post = Post::get(&*conn, id).unwrap();
Json(post.to_json(&*conn))
let post = <Post as Provider<PgConnection>>::get(&*conn, id).ok();
Json(json!(post))
}
// TODO: handle query params
#[get("/posts")]
fn list(conn: DbConn) -> Json<serde_json::Value> {
let post = <Post as Provider<PgConnection>>::list(&*conn, PostEndpoint::default());
Json(json!(post))
}