use geekorm::{Connection, prelude::*};
use super::Projects;
#[derive(Data, Debug, Default, Clone, PartialEq)]
pub enum ProjectStatus {
#[default]
Active,
Inactive,
Archived,
}
#[derive(Data, Debug, Default, Clone, PartialEq)]
pub enum ProjectType {
#[geekorm(aliases = "group,groups")]
Group,
#[default]
#[geekorm(aliases = "app,application,applications")]
Application,
#[geekorm(aliases = "server,servers")]
Server,
#[geekorm(aliases = "cluster")]
Cluster,
#[geekorm(aliases = "container,containers,docker")]
Container,
}
impl ProjectStatus {
pub async fn count_active(connection: &Connection<'_>) -> Result<i64, crate::KonarrError> {
Ok(Projects::row_count(
connection,
Projects::query_count()
.where_ne("status", ProjectStatus::Archived)
.build()?,
)
.await?)
}
pub async fn count_inactive(connection: &Connection<'_>) -> Result<i64, crate::KonarrError> {
Ok(Projects::row_count(
connection,
Projects::query_count()
.where_eq("status", ProjectStatus::Inactive)
.build()?,
)
.await?)
}
pub async fn count_archived(connection: &Connection<'_>) -> Result<i64, crate::KonarrError> {
Ok(Projects::row_count(
connection,
Projects::query_count()
.where_eq("status", ProjectStatus::Archived)
.build()?,
)
.await?)
}
}
impl ProjectType {
pub async fn count_servers(connection: &Connection<'_>) -> Result<i64, crate::KonarrError> {
Ok(Projects::row_count(
connection,
Projects::query_count()
.where_eq("project_type", ProjectType::Server)
.and()
.where_eq("status", ProjectStatus::Active)
.build()?,
)
.await?)
}
pub async fn count_containers(connection: &Connection<'_>) -> Result<i64, crate::KonarrError> {
Ok(Projects::row_count(
connection,
Projects::query_count()
.where_eq("project_type", ProjectType::Container)
.and()
.where_eq("status", ProjectStatus::Active)
.build()?,
)
.await?)
}
}