Fix workspace defaults

This commit is contained in:
Gregory Schier
2024-01-15 12:25:13 -08:00
parent d5459229b9
commit ad0b8a8e7d
2 changed files with 23 additions and 11 deletions

View File

@@ -284,10 +284,7 @@ async fn create_workspace(
let pool = &*db_instance.lock().await; let pool = &*db_instance.lock().await;
let created_workspace = models::upsert_workspace( let created_workspace = models::upsert_workspace(
pool, pool,
models::Workspace { models::Workspace::new(name.to_string()),
name: name.to_string(),
..Default::default()
},
) )
.await .await
.expect("Failed to create Workspace"); .expect("Failed to create Workspace");

View File

@@ -8,6 +8,10 @@ use sqlx::types::{Json, JsonValue};
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use tauri::AppHandle; use tauri::AppHandle;
fn default_true() -> bool {
true
}
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)] #[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]
pub struct Settings { pub struct Settings {
@@ -31,11 +35,26 @@ pub struct Workspace {
pub variables: Json<Vec<EnvironmentVariable>>, pub variables: Json<Vec<EnvironmentVariable>>,
// Settings // Settings
#[serde(default = "default_true")]
pub setting_validate_certificates: bool, pub setting_validate_certificates: bool,
#[serde(default = "default_true")]
pub setting_follow_redirects: bool, pub setting_follow_redirects: bool,
pub setting_request_timeout: i64, pub setting_request_timeout: i64,
} }
// Implement default for Workspace
impl Workspace {
pub(crate) fn new(name: String) -> Self {
Self {
name,
model: "workspace".to_string(),
setting_validate_certificates: true,
setting_follow_redirects: true,
..Default::default()
}
}
}
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)] #[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]
pub struct Environment { pub struct Environment {
@@ -48,14 +67,10 @@ pub struct Environment {
pub variables: Json<Vec<EnvironmentVariable>>, pub variables: Json<Vec<EnvironmentVariable>>,
} }
fn default_enabled() -> bool {
true
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]
pub struct EnvironmentVariable { pub struct EnvironmentVariable {
#[serde(default = "default_enabled")] #[serde(default = "default_true")]
pub enabled: bool, pub enabled: bool,
pub name: String, pub name: String,
pub value: String, pub value: String,
@@ -64,7 +79,7 @@ pub struct EnvironmentVariable {
#[derive(Debug, Clone, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]
pub struct HttpRequestHeader { pub struct HttpRequestHeader {
#[serde(default = "default_enabled")] #[serde(default = "default_true")]
pub enabled: bool, pub enabled: bool,
pub name: String, pub name: String,
pub value: String, pub value: String,
@@ -73,7 +88,7 @@ pub struct HttpRequestHeader {
#[derive(Debug, Clone, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]
pub struct HttpUrlParameter { pub struct HttpUrlParameter {
#[serde(default = "default_enabled")] #[serde(default = "default_true")]
pub enabled: bool, pub enabled: bool,
pub name: String, pub name: String,
pub value: String, pub value: String,