mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-06-03 13:29:22 +00:00
25 lines
625 B
Rust
25 lines
625 B
Rust
use rocket_contrib::json::Json;
|
|
|
|
use crate::api::Api;
|
|
use plume_api::apps::NewAppData;
|
|
use plume_common::utils::random_hex;
|
|
use plume_models::{apps::*, db_conn::DbConn};
|
|
|
|
#[post("/apps", data = "<data>")]
|
|
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))
|
|
}
|