fix: Correct pg_client.rs fetch_admins and server.rs AppState
- Remove duplicate fetch_admins definitions - Use tokio_postgres client.query() instead of sqlx - Fix sync_admins() call in full_sync() - Add AppState.auth field to hold AuthState - Update admin handlers to use AppState All tests passing: - Admin sync: working - Admin login: token generated - Admin verify: username verified - SQLite: admin record exists
This commit is contained in:
@@ -106,29 +106,32 @@ impl PgClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_admins(&self) -> Result<Vec<PgAdmin>> {
|
pub async fn fetch_admins(&self) -> Result<Vec<PgAdmin>> {
|
||||||
let rows = sqlx::query!(
|
let client = self.connect().await?;
|
||||||
"SELECT username, password as password_hash,
|
|
||||||
email, description, status, permissions, filters,
|
let rows = client
|
||||||
role_id, last_login, created_at, updated_at
|
.query(
|
||||||
FROM admins WHERE status = 1"
|
"SELECT username, password, email, description, status,
|
||||||
)
|
permissions, filters, role_id, last_login,
|
||||||
.fetch_all(&self.pool)
|
created_at, updated_at
|
||||||
.await?;
|
FROM admins WHERE status = 1",
|
||||||
|
&[],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let admins = rows
|
let admins = rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|row| PgAdmin {
|
.map(|row| PgAdmin {
|
||||||
username: row.username,
|
username: row.get::<_, String>(0),
|
||||||
password_hash: row.password_hash,
|
password_hash: row.get::<_, String>(1),
|
||||||
email: row.email,
|
email: row.get::<_, Option<String>>(2),
|
||||||
description: row.description,
|
description: row.get::<_, Option<String>>(3),
|
||||||
status: row.status,
|
status: row.get::<_, i32>(4),
|
||||||
permissions: row.permissions,
|
permissions: row.get::<_, String>(5),
|
||||||
filters: row.filters,
|
filters: row.get::<_, Option<String>>(6),
|
||||||
role_id: row.role_id.map(|v| v as i32),
|
role_id: row.get::<_, Option<i32>>(7),
|
||||||
last_login: row.last_login,
|
last_login: row.get::<_, i64>(8),
|
||||||
created_at: row.created_at,
|
created_at: row.get::<_, i64>(9),
|
||||||
updated_at: row.updated_at,
|
updated_at: row.get::<_, i64>(10),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user