diff options
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/models.rs | 12 | ||||
| -rw-r--r-- | makima/src/db/repository.rs | 20 |
2 files changed, 19 insertions, 13 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 121897d..c11150f 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -7,7 +7,6 @@ use utoipa::ToSchema; use uuid::Uuid; /// Default max retries for task daemon failover (3 attempts) -#[allow(dead_code)] fn default_max_retries() -> i32 { 3 } @@ -3051,19 +3050,24 @@ pub struct DirectiveOrderGroupListResponse { pub total: i64, } -/// User setting record from the database (key-value per owner). +// ============================================================================= +// User Settings Types +// ============================================================================= + +/// A user setting (feature flag / preference) stored in the database. #[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct UserSetting { pub id: Uuid, pub owner_id: Uuid, pub key: String, + #[sqlx(json)] pub value: serde_json::Value, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>, } -/// Request body for upserting a user setting. +/// Request to upsert (create or update) a user setting. #[derive(Debug, Deserialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct UpsertUserSettingRequest { @@ -3071,7 +3075,7 @@ pub struct UpsertUserSettingRequest { pub value: serde_json::Value, } -/// Response containing a list of user settings. +/// Response wrapping a list of user settings. #[derive(Debug, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct UserSettingsResponse { diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 10633d5..5a912e4 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -21,7 +21,6 @@ use super::models::{ PhaseDefinition, SupervisorHeartbeatRecord, SupervisorState, Task, TaskCheckpoint, TaskEvent, TaskSummary, UpdateContractRequest, UpdateFileRequest, UpdateTaskRequest, UpdateTemplateRequest, - UserSetting, }; /// Repository error types. @@ -4912,7 +4911,6 @@ pub async fn sync_supervisor_state( // ============================================================================= /// Helper to truncate string to max length -#[allow(dead_code)] fn truncate_string(s: &str, max_len: usize) -> String { if s.len() <= max_len { s.to_string() @@ -6700,9 +6698,11 @@ pub async fn get_available_orders_for_dog_pickup( .await } -// ─── User Settings ─────────────────────────────────────────────────────────── +// ============================================================================= +// User Settings +// ============================================================================= -/// Get all settings for a given owner. +/// Get all settings for a user. pub async fn get_user_settings( pool: &PgPool, owner_id: Uuid, @@ -6720,7 +6720,7 @@ pub async fn get_user_settings( .await } -/// Get a single setting by owner and key. +/// Get a specific setting by key for a user. pub async fn get_user_setting( pool: &PgPool, owner_id: Uuid, @@ -6739,7 +6739,7 @@ pub async fn get_user_setting( .await } -/// Upsert a user setting (insert or update on conflict). +/// Upsert (create or update) a user setting. pub async fn upsert_user_setting( pool: &PgPool, owner_id: Uuid, @@ -6750,8 +6750,9 @@ pub async fn upsert_user_setting( r#" INSERT INTO user_settings (owner_id, key, value) VALUES ($1, $2, $3) - ON CONFLICT (owner_id, key) DO UPDATE - SET value = EXCLUDED.value, updated_at = now() + ON CONFLICT (owner_id, key) DO UPDATE SET + value = EXCLUDED.value, + updated_at = NOW() RETURNING id, owner_id, key, value, created_at, updated_at "#, ) @@ -6762,7 +6763,7 @@ pub async fn upsert_user_setting( .await } -/// Delete a user setting. Returns true if a row was deleted. +/// Delete a user setting by key. Returns true if a row was deleted. pub async fn delete_user_setting( pool: &PgPool, owner_id: Uuid, @@ -6778,6 +6779,7 @@ pub async fn delete_user_setting( .bind(key) .execute(pool) .await?; + Ok(result.rows_affected() > 0) } |
