feat: complete NX9-Auth management and integrity hardening

This commit is contained in:
thakares committed 2026-07-24 16:18:48 +05:30
1 parent dc5417334b
commit a969f9c571
59 files changed
+6508 -290

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
use crate::db::models::GlobalSlug;
use crate::db::repository::traits::GlobalSlugsRepository;
use sqlx::SqlitePool;
pub struct SqliteGlobalSlugsRepository {
pub pool: SqlitePool,
}
#[async_trait::async_trait]
impl GlobalSlugsRepository for SqliteGlobalSlugsRepository {
async fn find_by_slug(&self, slug: &str) -> Result<Option<GlobalSlug>, sqlx::Error> {
sqlx::query_as::<_, GlobalSlug>(
"SELECT slug, entity_type, entity_id, tenant_id, created_at FROM global_slugs WHERE slug = ?"
)
.bind(slug)
.fetch_optional(&self.pool)
.await
}
}
pub async fn reserve_slug_sqlite(
conn: &mut sqlx::SqliteConnection,
slug: &str,
entity_type: &str,
entity_id: &str,
tenant_id: &str,
) -> Result<(), sqlx::Error> {
sqlx::query(
"INSERT INTO global_slugs (slug, entity_type, entity_id, tenant_id) VALUES (?, ?, ?, ?)",
)
.bind(slug)
.bind(entity_type)
.bind(entity_id)
.bind(tenant_id)
.execute(conn)
.await?;
Ok(())
}
pub async fn release_slug_sqlite(
conn: &mut sqlx::SqliteConnection,
entity_type: &str,
entity_id: &str,
) -> Result<u64, sqlx::Error> {
let res = sqlx::query("DELETE FROM global_slugs WHERE entity_type = ? AND entity_id = ?")
.bind(entity_type)
.bind(entity_id)
.execute(conn)
.await?;
Ok(res.rows_affected())
}
pub async fn release_slug_by_name_sqlite(
conn: &mut sqlx::SqliteConnection,
slug: &str,
entity_type: &str,
entity_id: &str,
) -> Result<u64, sqlx::Error> {
let res = sqlx::query(
"DELETE FROM global_slugs WHERE slug = ? AND entity_type = ? AND entity_id = ?",
)
.bind(slug)
.bind(entity_type)
.bind(entity_id)
.execute(conn)
.await?;
Ok(res.rows_affected())
}