use crate::error::ServiceError;
use molten_core::WorkflowDefinition;
use molten_storage_seaorm::repo::WorkflowRepository;
use sea_orm::DatabaseConnection;
pub struct WorkflowService {
db: DatabaseConnection,
}
impl WorkflowService {
pub fn new(db: DatabaseConnection) -> Self {
Self { db }
}
pub async fn save_workflow(
&self,
workflow: WorkflowDefinition,
) -> Result<WorkflowDefinition, ServiceError> {
WorkflowRepository::save(&self.db, &workflow)
.await
.map_err(ServiceError::Internal)?;
Ok(workflow)
}
pub async fn get_workflow(&self, id: &str) -> Result<WorkflowDefinition, ServiceError> {
WorkflowRepository::find_by_id(&self.db, id)
.await
.map_err(ServiceError::Internal)?
.ok_or_else(|| ServiceError::Internal(anyhow::anyhow!("Workflow not found")))
}
}