feat(saas): wire llm_routing into account CRUD and auth responses
- Add llm_routing to all list_accounts/get_account SQL queries and JSON responses - Add llm_routing to UpdateAccountRequest with COALESCE update - Add llm_routing to AccountPublic struct in auth types - Wire llm_routing into register (default 'local'), login, and me handlers - Add llm_routing field to AccountRow, AccountAuthRow, AccountLoginRow model structs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -111,8 +111,8 @@ pub async fn register(
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
|
||||
sqlx::query(
|
||||
"INSERT INTO accounts (id, username, email, password_hash, display_name, role, status, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, 'active', $7, $7)"
|
||||
"INSERT INTO accounts (id, username, email, password_hash, display_name, role, status, created_at, updated_at, llm_routing)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, 'active', $7, $7, 'local')"
|
||||
)
|
||||
.bind(&account_id)
|
||||
.bind(&req.username)
|
||||
@@ -159,6 +159,7 @@ pub async fn register(
|
||||
status: "active".into(),
|
||||
totp_enabled: false,
|
||||
created_at: now,
|
||||
llm_routing: "local".into(),
|
||||
},
|
||||
};
|
||||
let jar = set_auth_cookies(jar, &resp.token, &refresh_token);
|
||||
@@ -176,7 +177,7 @@ pub async fn login(
|
||||
let row: Option<AccountLoginRow> =
|
||||
sqlx::query_as(
|
||||
"SELECT id, username, email, display_name, role, status, totp_enabled,
|
||||
password_hash, totp_secret, created_at
|
||||
password_hash, totp_secret, created_at, llm_routing
|
||||
FROM accounts WHERE username = $1 OR email = $1"
|
||||
)
|
||||
.bind(&req.username)
|
||||
@@ -245,6 +246,7 @@ pub async fn login(
|
||||
account: AccountPublic {
|
||||
id: r.id, username: r.username, email: r.email, display_name: r.display_name,
|
||||
role: r.role, status: r.status, totp_enabled: r.totp_enabled, created_at: r.created_at,
|
||||
llm_routing: r.llm_routing,
|
||||
},
|
||||
};
|
||||
let jar = set_auth_cookies(jar, &resp.token, &refresh_token);
|
||||
@@ -349,7 +351,7 @@ pub async fn me(
|
||||
) -> SaasResult<Json<AccountPublic>> {
|
||||
let row: Option<AccountAuthRow> =
|
||||
sqlx::query_as(
|
||||
"SELECT id, username, email, display_name, role, status, totp_enabled, created_at
|
||||
"SELECT id, username, email, display_name, role, status, totp_enabled, created_at, llm_routing
|
||||
FROM accounts WHERE id = $1"
|
||||
)
|
||||
.bind(&ctx.account_id)
|
||||
@@ -361,6 +363,7 @@ pub async fn me(
|
||||
Ok(Json(AccountPublic {
|
||||
id: r.id, username: r.username, email: r.email, display_name: r.display_name,
|
||||
role: r.role, status: r.status, totp_enabled: r.totp_enabled, created_at: r.created_at,
|
||||
llm_routing: r.llm_routing,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ pub struct AccountPublic {
|
||||
pub status: String,
|
||||
pub totp_enabled: bool,
|
||||
pub created_at: String,
|
||||
pub llm_routing: String,
|
||||
}
|
||||
|
||||
/// 认证上下文 (注入到 request extensions)
|
||||
|
||||
Reference in New Issue
Block a user