2018-09-25 21:45:32 +02:00
|
|
|
use canapi::Provider;
|
|
|
|
use diesel::PgConnection;
|
2018-09-19 16:49:34 +02:00
|
|
|
use rocket_contrib::Json;
|
|
|
|
use serde_json;
|
|
|
|
|
2018-09-25 21:45:32 +02:00
|
|
|
use plume_api::posts::PostEndpoint;
|
2018-09-19 16:49:34 +02:00
|
|
|
use plume_models::db_conn::DbConn;
|
|
|
|
use plume_models::posts::Post;
|
|
|
|
|
|
|
|
#[get("/posts/<id>")]
|
|
|
|
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
2018-09-25 21:45:32 +02:00
|
|
|
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))
|
2018-09-19 16:49:34 +02:00
|
|
|
}
|