summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs20
1 files changed, 11 insertions, 9 deletions
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)
}