2018-12-06 18:54:16 +01:00
|
|
|
use rocket_contrib::json::Json;
|
2018-10-21 18:22:27 +02:00
|
|
|
|
2019-04-28 23:17:21 +02:00
|
|
|
use crate::api::Api;
|
|
|
|
use plume_api::apps::NewAppData;
|
|
|
|
use plume_common::utils::random_hex;
|
|
|
|
use plume_models::{apps::*, db_conn::DbConn};
|
2018-10-21 18:22:27 +02:00
|
|
|
|
|
|
|
#[post("/apps", data = "<data>")]
|
2019-04-28 23:17:21 +02:00
|
|
|
pub fn create(conn: DbConn, data: Json<NewAppData>) -> Api<App> {
|
|
|
|
let client_id = random_hex();
|
|
|
|
let client_secret = random_hex();
|
|
|
|
let app = App::insert(
|
|
|
|
&*conn,
|
|
|
|
NewApp {
|
|
|
|
name: data.name.clone(),
|
|
|
|
client_id,
|
|
|
|
client_secret,
|
|
|
|
redirect_uri: data.redirect_uri.clone(),
|
|
|
|
website: data.website.clone(),
|
|
|
|
},
|
|
|
|
)?;
|
|
|
|
|
|
|
|
Ok(Json(app))
|
2018-10-21 18:22:27 +02:00
|
|
|
}
|