Skip to content
Clone
ef0b83a
42 lines 1.1 KB Rust
use models::space::spaces;
use uuid::Uuid;
use crate::authority;
use crate::errors::SpaceError;
use crate::services::service::SpaceService;
pub async fn find_active_space_by_name(
state: &export::AppState,
caller: i64,
space_name: &str,
) -> Result<spaces::Model, SpaceError> {
let lower_name = space_name.trim().to_lowercase();
if lower_name.is_empty() {
return Err(SpaceError::NotFound);
}
let space = authority::space_by_slug(state, caller, &lower_name).await?;
if !authority::space_is_active(&space) {
return Err(SpaceError::NotFound);
}
Ok(space)
}
pub async fn lookup_space_by_name(
service: &SpaceService,
caller: i64,
space_name: &str,
) -> Result<spaces::Model, SpaceError> {
find_active_space_by_name(&service.state, caller, space_name).await
}
pub async fn lookup_space_by_id(
service: &SpaceService,
caller: i64,
space_id: Uuid,
) -> Result<spaces::Model, SpaceError> {
let space = authority::space_by_id(&service.state, caller, space_id).await?;
if !authority::space_is_active(&space) {
return Err(SpaceError::NotFound);
}
Ok(space)
}