Mount the API endpoints
This commit is contained in:
+12
-2
@@ -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))
|
||||
}
|
||||
|
||||
+4
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
extern crate activitypub;
|
||||
extern crate atom_syndication;
|
||||
extern crate canapi;
|
||||
extern crate chrono;
|
||||
extern crate colored;
|
||||
extern crate diesel;
|
||||
@@ -12,6 +13,7 @@ extern crate gettextrs;
|
||||
extern crate guid_create;
|
||||
extern crate heck;
|
||||
extern crate multipart;
|
||||
extern crate plume_api;
|
||||
extern crate plume_common;
|
||||
extern crate plume_models;
|
||||
#[macro_use]
|
||||
@@ -144,7 +146,8 @@ fn main() {
|
||||
routes::errors::csrf_violation
|
||||
])
|
||||
.mount("/api/v1", routes![
|
||||
api::posts::get
|
||||
api::posts::get,
|
||||
api::posts::list
|
||||
])
|
||||
.catch(catchers![
|
||||
routes::errors::not_found,
|
||||
|
||||
Reference in New Issue
Block a user