NewBotVersion

This commit is contained in:
Ilion Beyst 2022-07-07 18:57:46 +02:00
parent d7b7585dd7
commit 6ec792e3bd
3 changed files with 14 additions and 11 deletions

View file

@ -45,9 +45,10 @@ pub fn find_all_bots(conn: &PgConnection) -> QueryResult<Vec<Bot>> {
#[derive(Insertable)] #[derive(Insertable)]
#[table_name = "bot_versions"] #[table_name = "bot_versions"]
pub struct NewCodeBundle<'a> { pub struct NewBotVersion<'a> {
pub bot_id: Option<i32>, pub bot_id: Option<i32>,
pub code_bundle_path: &'a str, pub code_bundle_path: Option<&'a str>,
pub container_digest: Option<&'a str>,
} }
#[derive(Queryable, Serialize, Deserialize, Debug)] #[derive(Queryable, Serialize, Deserialize, Debug)]
@ -59,12 +60,12 @@ pub struct BotVersion {
pub container_digest: Option<String>, pub container_digest: Option<String>,
} }
pub fn create_code_bundle( pub fn create_bot_version(
new_code_bundle: &NewCodeBundle, new_bot_version: &NewBotVersion,
conn: &PgConnection, conn: &PgConnection,
) -> QueryResult<BotVersion> { ) -> QueryResult<BotVersion> {
diesel::insert_into(bot_versions::table) diesel::insert_into(bot_versions::table)
.values(new_code_bundle) .values(new_bot_version)
.get_result(conn) .get_result(conn)
} }

View file

@ -15,9 +15,10 @@ pub fn save_code_bundle(
std::fs::create_dir(&code_bundle_dir).unwrap(); std::fs::create_dir(&code_bundle_dir).unwrap();
std::fs::write(code_bundle_dir.join("bot.py"), bot_code).unwrap(); std::fs::write(code_bundle_dir.join("bot.py"), bot_code).unwrap();
let new_code_bundle = db::bots::NewCodeBundle { let new_code_bundle = db::bots::NewBotVersion {
bot_id, bot_id,
code_bundle_path: &bundle_name, code_bundle_path: Some(&bundle_name),
container_digest: None,
}; };
db::bots::create_code_bundle(&new_code_bundle, conn) db::bots::create_bot_version(&new_code_bundle, conn)
} }

View file

@ -213,12 +213,13 @@ pub async fn upload_code_multipart(
.extract(bots_dir.join(&folder_name)) .extract(bots_dir.join(&folder_name))
.map_err(|_| StatusCode::BAD_REQUEST)?; .map_err(|_| StatusCode::BAD_REQUEST)?;
let bundle = bots::NewCodeBundle { let bot_version = bots::NewBotVersion {
bot_id: Some(bot.id), bot_id: Some(bot.id),
code_bundle_path: &folder_name, code_bundle_path: Some(&folder_name),
container_digest: None,
}; };
let code_bundle = let code_bundle =
bots::create_code_bundle(&bundle, &conn).expect("Failed to create code bundle"); bots::create_bot_version(&bot_version, &conn).expect("Failed to create code bundle");
Ok(Json(code_bundle)) Ok(Json(code_bundle))
} }