don't allow overwriting bots for now
This commit is contained in:
parent
5265e19507
commit
0f7c3c3102
1 changed files with 3 additions and 3 deletions
|
@ -23,13 +23,13 @@ pub struct SaveBotParams {
|
||||||
pub async fn save_bot(
|
pub async fn save_bot(
|
||||||
Json(params): Json<SaveBotParams>,
|
Json(params): Json<SaveBotParams>,
|
||||||
conn: DatabaseConnection,
|
conn: DatabaseConnection,
|
||||||
) -> Result<(), StatusCode> {
|
) -> Result<Json<Bot>, StatusCode> {
|
||||||
// TODO: authorization
|
// TODO: authorization
|
||||||
let res = bots::find_bot_by_name(¶ms.bot_name, &conn)
|
let res = bots::find_bot_by_name(¶ms.bot_name, &conn)
|
||||||
.optional()
|
.optional()
|
||||||
.expect("could not run query");
|
.expect("could not run query");
|
||||||
let bot = match res {
|
let bot = match res {
|
||||||
Some(bot) => bot,
|
Some(_bot) => return Err(StatusCode::FORBIDDEN),
|
||||||
None => {
|
None => {
|
||||||
let new_bot = bots::NewBot {
|
let new_bot = bots::NewBot {
|
||||||
owner_id: None,
|
owner_id: None,
|
||||||
|
@ -41,7 +41,7 @@ pub async fn save_bot(
|
||||||
};
|
};
|
||||||
let _code_bundle =
|
let _code_bundle =
|
||||||
save_code_bundle(¶ms.code, Some(bot.id), &conn).expect("failed to save code bundle");
|
save_code_bundle(¶ms.code, Some(bot.id), &conn).expect("failed to save code bundle");
|
||||||
Ok(())
|
Ok(Json(bot))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
Loading…
Reference in a new issue