linting, tenant slug -> name
This commit is contained in:
+15
-15
@@ -24,9 +24,9 @@ impl TenantRepository {
|
||||
dsl::tenants.find(tenant_id).first(conn).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn get_by_slug(conn: &mut PgConnection, slug: &str) -> AppResult<Tenant> {
|
||||
pub fn get_by_name(conn: &mut PgConnection, name: &str) -> AppResult<Tenant> {
|
||||
dsl::tenants
|
||||
.filter(dsl::slug.eq(slug))
|
||||
.filter(dsl::name.eq(name))
|
||||
.first(conn)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
@@ -47,28 +47,28 @@ impl TenantService {
|
||||
Ok(tenant)
|
||||
}
|
||||
|
||||
pub fn get_by_slug(&self, slug: &str) -> AppResult<Tenant> {
|
||||
let slug_owned = slug.to_owned();
|
||||
let tenant = self.load(|conn| TenantRepository::get_by_slug(conn, &slug_owned))?;
|
||||
pub fn get_by_name(&self, name: &str) -> AppResult<Tenant> {
|
||||
let name_owned = name.to_owned();
|
||||
let tenant = self.load(|conn| TenantRepository::get_by_name(conn, &name_owned))?;
|
||||
Ok(tenant)
|
||||
}
|
||||
|
||||
pub fn tenant_id_for_slug(&self, slug: &str) -> AppResult<Uuid> {
|
||||
Ok(self.get_by_slug(slug)?.id)
|
||||
pub fn tenant_id_for_name(&self, name: &str) -> AppResult<Uuid> {
|
||||
Ok(self.get_by_name(name)?.id)
|
||||
}
|
||||
|
||||
pub fn create_tenant(
|
||||
&self,
|
||||
slug: &str,
|
||||
name: &str,
|
||||
storage_root: Option<&str>,
|
||||
quickwit_index: Option<&str>,
|
||||
status: TenantStatus,
|
||||
initial_members: &[Uuid],
|
||||
created_by: Option<Uuid>,
|
||||
) -> AppResult<Tenant> {
|
||||
let slug = slug.trim();
|
||||
if slug.is_empty() {
|
||||
return Err(AppError::bad_request("tenant slug must not be empty"));
|
||||
let name = name.trim();
|
||||
if name.is_empty() {
|
||||
return Err(AppError::bad_request("tenant name must not be empty"));
|
||||
}
|
||||
|
||||
let mut conn = self.pool.get().map_err(|err| {
|
||||
@@ -77,11 +77,11 @@ impl TenantService {
|
||||
})?;
|
||||
|
||||
let exists: bool =
|
||||
select(exists(dsl::tenants.filter(dsl::slug.eq(slug)))).get_result(&mut conn)?;
|
||||
select(exists(dsl::tenants.filter(dsl::name.eq(name)))).get_result(&mut conn)?;
|
||||
if exists {
|
||||
return Err(AppError::conflict(format!(
|
||||
"tenant '{}' already exists",
|
||||
slug
|
||||
name
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ impl TenantService {
|
||||
diesel::insert_into(dsl::tenants)
|
||||
.values((
|
||||
dsl::id.eq(id),
|
||||
dsl::slug.eq(slug),
|
||||
dsl::name.eq(name),
|
||||
dsl::storage_root.eq(Some(storage_root.clone())),
|
||||
dsl::quickwit_index.eq(Some(quickwit_index.clone())),
|
||||
dsl::config.eq(json!({})),
|
||||
@@ -150,7 +150,7 @@ impl FromRequestParts<AppState> for TenantContext {
|
||||
) -> Result<Self, Self::Rejection> {
|
||||
let tenant = state
|
||||
.tenants
|
||||
.get_by_slug(&state.config.default_tenant_slug)?;
|
||||
.get_by_name(&state.config.default_tenant_name)?;
|
||||
Ok(Self { tenant })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user