Add an API endpoint to register apps

This commit is contained in:
Baptiste Gelez
2018-10-21 17:22:27 +01:00
parent 4c8a727e9e
commit f2190adfc2
6 changed files with 97 additions and 1 deletions
+16
View File
@@ -0,0 +1,16 @@
use canapi::Provider;
use rocket_contrib::Json;
use serde_json;
use plume_api::apps::AppEndpoint;
use plume_models::{
Connection,
db_conn::DbConn,
apps::App,
};
#[post("/apps", data = "<data>")]
fn create(conn: DbConn, data: Json<AppEndpoint>) -> Json<serde_json::Value> {
let post = <App as Provider<Connection>>::create(&*conn, (*data).clone()).ok();
Json(json!(post))
}
+1
View File
@@ -1 +1,2 @@
pub mod apps;
pub mod posts;
+3
View File
@@ -156,6 +156,8 @@ fn main() {
routes::errors::csrf_violation
])
.mount("/api/v1", routes![
api::apps::create,
api::posts::get,
api::posts::list,
])
@@ -176,6 +178,7 @@ fn main() {
("/@/<name>/inbox".to_owned(), "/@/<name>/inbox".to_owned(), rocket::http::Method::Post),
("/login".to_owned(), "/login".to_owned(), rocket::http::Method::Post),
("/users/new".to_owned(), "/users/new".to_owned(), rocket::http::Method::Post),
("/api/v1/<endpoint>".to_owned(), "/api/v1/<endpoint>".to_owned(), rocket::http::Method::Post)
])
.finalize().expect("main: csrf fairing creation error"))
.launch();