2025-10-06 10:30:17 -03:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use sqlx::PgPool;
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Organization {
|
|
|
|
|
pub org_id: Uuid,
|
2025-10-06 10:30:17 -03:00
|
|
|
pub name: String,
|
|
|
|
|
pub slug: String,
|
2025-10-06 20:06:43 -03:00
|
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
2025-10-06 10:30:17 -03:00
|
|
|
}
|
|
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub struct OrganizationService {
|
|
|
|
|
pub pool: PgPool,
|
2025-10-06 10:30:17 -03:00
|
|
|
}
|
|
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
impl OrganizationService {
|
|
|
|
|
pub fn new(pool: PgPool) -> Self {
|
|
|
|
|
Self { pool }
|
2025-10-06 10:30:17 -03:00
|
|
|
}
|
|
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub async fn create_organization(
|
|
|
|
|
&self,
|
|
|
|
|
name: &str,
|
|
|
|
|
slug: &str,
|
|
|
|
|
) -> Result<Organization, Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
|
let org = Organization {
|
|
|
|
|
org_id: Uuid::new_v4(),
|
|
|
|
|
name: name.to_string(),
|
|
|
|
|
slug: slug.to_string(),
|
|
|
|
|
created_at: chrono::Utc::now(),
|
|
|
|
|
};
|
|
|
|
|
Ok(org)
|
|
|
|
|
}
|
2025-10-06 10:30:17 -03:00
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub async fn get_organization(
|
|
|
|
|
&self,
|
|
|
|
|
org_id: Uuid,
|
|
|
|
|
) -> Result<Option<Organization>, Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
|
Ok(None)
|
|
|
|
|
}
|
2025-10-06 10:30:17 -03:00
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub async fn list_organizations(
|
|
|
|
|
&self,
|
|
|
|
|
_limit: i64,
|
|
|
|
|
_offset: i64,
|
|
|
|
|
) -> Result<Vec<Organization>, Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
|
Ok(vec![])
|
|
|
|
|
}
|
2025-10-06 10:30:17 -03:00
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub async fn update_organization(
|
|
|
|
|
&self,
|
|
|
|
|
_org_id: Uuid,
|
|
|
|
|
_name: Option<&str>,
|
|
|
|
|
_slug: Option<&str>,
|
|
|
|
|
) -> Result<Option<Organization>, Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
|
Ok(None)
|
|
|
|
|
}
|
2025-10-06 10:30:17 -03:00
|
|
|
|
2025-10-06 20:06:43 -03:00
|
|
|
pub async fn delete_organization(
|
|
|
|
|
&self,
|
|
|
|
|
_org_id: Uuid,
|
|
|
|
|
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
|
Ok(true)
|
|
|
|
|
}
|
2025-10-06 10:30:17 -03:00
|
|
|
}
|