mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-23 10:30:41 +00:00
Mount the API endpoints
This commit is contained in:
parent
472da486e9
commit
f893056d6d
4 changed files with 22 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1459,6 +1459,7 @@ version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"activitypub 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"atom_syndication 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"atom_syndication 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"canapi 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"diesel 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"diesel 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1468,6 +1469,7 @@ dependencies = [
|
||||||
"guid-create 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"guid-create 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"multipart 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"multipart 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"plume-api 0.1.0",
|
||||||
"plume-common 0.2.0",
|
"plume-common 0.2.0",
|
||||||
"plume-models 0.2.0",
|
"plume-models 0.2.0",
|
||||||
"rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=55459db7732b9a240826a5c120c650f87e3372ce)",
|
"rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=55459db7732b9a240826a5c120c650f87e3372ce)",
|
||||||
|
|
|
@ -5,6 +5,7 @@ version = "0.2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.3"
|
activitypub = "0.1.3"
|
||||||
atom_syndication = "0.6"
|
atom_syndication = "0.6"
|
||||||
|
canapi = "0.1"
|
||||||
colored = "1.6"
|
colored = "1.6"
|
||||||
dotenv = "0.13"
|
dotenv = "0.13"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
|
@ -30,6 +31,9 @@ version = "0.4"
|
||||||
features = ["postgres", "r2d2", "chrono"]
|
features = ["postgres", "r2d2", "chrono"]
|
||||||
version = "*"
|
version = "*"
|
||||||
|
|
||||||
|
[dependencies.plume-api]
|
||||||
|
path = "plume-api"
|
||||||
|
|
||||||
[dependencies.plume-common]
|
[dependencies.plume-common]
|
||||||
path = "plume-common"
|
path = "plume-common"
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
|
use canapi::Provider;
|
||||||
|
use diesel::PgConnection;
|
||||||
use rocket_contrib::Json;
|
use rocket_contrib::Json;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
|
use plume_api::posts::PostEndpoint;
|
||||||
use plume_models::db_conn::DbConn;
|
use plume_models::db_conn::DbConn;
|
||||||
use plume_models::posts::Post;
|
use plume_models::posts::Post;
|
||||||
|
|
||||||
#[get("/posts/<id>")]
|
#[get("/posts/<id>")]
|
||||||
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
||||||
let post = Post::get(&*conn, id).unwrap();
|
let post = <Post as Provider<PgConnection>>::get(&*conn, id).ok();
|
||||||
Json(post.to_json(&*conn))
|
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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
extern crate activitypub;
|
extern crate activitypub;
|
||||||
extern crate atom_syndication;
|
extern crate atom_syndication;
|
||||||
|
extern crate canapi;
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate colored;
|
extern crate colored;
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
@ -12,6 +13,7 @@ extern crate gettextrs;
|
||||||
extern crate guid_create;
|
extern crate guid_create;
|
||||||
extern crate heck;
|
extern crate heck;
|
||||||
extern crate multipart;
|
extern crate multipart;
|
||||||
|
extern crate plume_api;
|
||||||
extern crate plume_common;
|
extern crate plume_common;
|
||||||
extern crate plume_models;
|
extern crate plume_models;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -144,7 +146,8 @@ fn main() {
|
||||||
routes::errors::csrf_violation
|
routes::errors::csrf_violation
|
||||||
])
|
])
|
||||||
.mount("/api/v1", routes![
|
.mount("/api/v1", routes![
|
||||||
api::posts::get
|
api::posts::get,
|
||||||
|
api::posts::list
|
||||||
])
|
])
|
||||||
.catch(catchers![
|
.catch(catchers![
|
||||||
routes::errors::not_found,
|
routes::errors::not_found,
|
||||||
|
|
Loading…
Reference in a new issue