|
|
|
|
@ -17,6 +17,7 @@ struct SettingsRow {
|
|
|
|
|
max_age_days: i32,
|
|
|
|
|
categories: serde_json::Value,
|
|
|
|
|
max_items_per_category: i32,
|
|
|
|
|
max_articles_per_source: i32,
|
|
|
|
|
search_agent_behavior: String,
|
|
|
|
|
ai_provider: String,
|
|
|
|
|
ai_model: String,
|
|
|
|
|
@ -40,6 +41,7 @@ impl TryFrom<SettingsRow> for UserSettings {
|
|
|
|
|
max_age_days: row.max_age_days,
|
|
|
|
|
categories,
|
|
|
|
|
max_items_per_category: row.max_items_per_category,
|
|
|
|
|
max_articles_per_source: row.max_articles_per_source,
|
|
|
|
|
search_agent_behavior: row.search_agent_behavior,
|
|
|
|
|
ai_provider: row.ai_provider,
|
|
|
|
|
ai_model: row.ai_model,
|
|
|
|
|
@ -66,10 +68,10 @@ pub async fn get_or_create_default(
|
|
|
|
|
|
|
|
|
|
let row = sqlx::query_as::<_, SettingsRow>(
|
|
|
|
|
r#"
|
|
|
|
|
INSERT INTO settings (user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
|
|
|
INSERT INTO settings (user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, max_articles_per_source)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
|
|
|
|
ON CONFLICT (user_id) DO UPDATE SET user_id = settings.user_id
|
|
|
|
|
RETURNING user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, updated_at
|
|
|
|
|
RETURNING user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, max_articles_per_source, updated_at
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.bind(user_id)
|
|
|
|
|
@ -83,6 +85,7 @@ pub async fn get_or_create_default(
|
|
|
|
|
.bind(&defaults.ai_model_writing)
|
|
|
|
|
.bind(defaults.rate_limit_max_requests)
|
|
|
|
|
.bind(defaults.rate_limit_time_window_seconds)
|
|
|
|
|
.bind(defaults.max_articles_per_source)
|
|
|
|
|
.fetch_one(pool)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
@ -101,8 +104,8 @@ pub async fn upsert(
|
|
|
|
|
|
|
|
|
|
let row = sqlx::query_as::<_, SettingsRow>(
|
|
|
|
|
r#"
|
|
|
|
|
INSERT INTO settings (user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
|
|
|
INSERT INTO settings (user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, max_articles_per_source)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
|
|
|
|
ON CONFLICT (user_id) DO UPDATE SET
|
|
|
|
|
theme = EXCLUDED.theme,
|
|
|
|
|
max_age_days = EXCLUDED.max_age_days,
|
|
|
|
|
@ -114,8 +117,9 @@ pub async fn upsert(
|
|
|
|
|
ai_model_writing = EXCLUDED.ai_model_writing,
|
|
|
|
|
rate_limit_max_requests = EXCLUDED.rate_limit_max_requests,
|
|
|
|
|
rate_limit_time_window_seconds = EXCLUDED.rate_limit_time_window_seconds,
|
|
|
|
|
max_articles_per_source = EXCLUDED.max_articles_per_source,
|
|
|
|
|
updated_at = now()
|
|
|
|
|
RETURNING user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, updated_at
|
|
|
|
|
RETURNING user_id, theme, max_age_days, categories, max_items_per_category, search_agent_behavior, ai_provider, ai_model, ai_model_writing, rate_limit_max_requests, rate_limit_time_window_seconds, max_articles_per_source, updated_at
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.bind(user_id)
|
|
|
|
|
@ -129,6 +133,7 @@ pub async fn upsert(
|
|
|
|
|
.bind(&req.ai_model_writing)
|
|
|
|
|
.bind(req.rate_limit_max_requests)
|
|
|
|
|
.bind(req.rate_limit_time_window_seconds)
|
|
|
|
|
.bind(req.max_articles_per_source)
|
|
|
|
|
.fetch_one(pool)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|