Add an API endpoint to register apps
This commit is contained in:
@@ -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 +1,2 @@
|
||||
pub mod apps;
|
||||
pub mod posts;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user