Menu
Public repository / 3503b684768a57d3fa15dd6fd3c2af86320c5b56
AkurAI-DNS / src/models.rs
Latest change 3503b684768a57d3fa15dd6fd3c2af86320c5b56 - feat: add domain_ownerships table and CRUD API with tenant isolation (AKURAI-DNS-5) by agent
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DomainState {
Requested,
Verifying,
Provisioned,
Renewing,
Failed,
Retired,
}
impl DomainState {
pub fn as_str(&self) -> &'static str {
match self {
DomainState::Requested => "requested",
DomainState::Verifying => "verifying",
DomainState::Provisioned => "provisioned",
DomainState::Renewing => "renewing",
DomainState::Failed => "failed",
DomainState::Retired => "retired",
}
}
pub fn from_str(s: &str) -> Option<Self> {
match s {
"requested" => Some(DomainState::Requested),
"verifying" => Some(DomainState::Verifying),
"provisioned" => Some(DomainState::Provisioned),
"renewing" => Some(DomainState::Renewing),
"failed" => Some(DomainState::Failed),
"retired" => Some(DomainState::Retired),
_ => None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DomainOwnership {
pub id: i64,
pub org_id: String,
pub workspace_id: String,
pub domain: String,
pub state: DomainState,
pub verification_token: Option<String>,
pub verified_at: Option<String>,
pub provisioned_at: Option<String>,
pub expires_at: Option<String>,
pub created_at: String,
pub updated_at: String,
}
/// JSON shape for POST /api/domains — only the domain is caller-supplied.
#[derive(Debug, Deserialize)]
pub struct CreateDomainRequest {
pub domain: String,
}
/// JSON shape for returning a created or listed domain.
#[derive(Debug, Serialize)]
pub struct DomainResponse {
pub id: i64,
pub org_id: String,
pub workspace_id: String,
pub domain: String,
pub state: String,
pub verification_token: Option<String>,
pub verified_at: Option<String>,
pub provisioned_at: Option<String>,
pub expires_at: Option<String>,
pub created_at: String,
pub updated_at: String,
}
impl From<DomainOwnership> for DomainResponse {
fn from(d: DomainOwnership) -> Self {
DomainResponse {
id: d.id,
org_id: d.org_id,
workspace_id: d.workspace_id,
domain: d.domain,
state: d.state.as_str().to_string(),
verification_token: d.verification_token,
verified_at: d.verified_at,
provisioned_at: d.provisioned_at,
expires_at: d.expires_at,
created_at: d.created_at,
updated_at: d.updated_at,
}
}
}