fluxpro_engine/db_models/
process_def_db.rs1use crate::models::process_def::ProcessDefinition;
4use crate::models::process_def_error::CreateProcessError;
5use chrono::{DateTime, Utc};
6use log::error;
7use serde_json::Value;
8use sqlx::FromRow;
9use uuid::Uuid;
10
11#[derive(Debug, FromRow, PartialEq)]
13pub struct ProcessDefDb {
14 pub uuid: Uuid,
16 pub created_at: DateTime<Utc>,
18 pub key_: String,
20 pub version: String,
22 pub index_id: i32,
24 pub status: String,
26 pub effective_from: DateTime<Utc>,
28 pub deprecated_at: Option<DateTime<Utc>>,
30 pub version_comment: Option<String>,
32 pub definition: Value,
34}
35
36impl TryInto<ProcessDefinition> for ProcessDefDb {
37 type Error = CreateProcessError;
38
39 fn try_into(self) -> Result<ProcessDefinition, Self::Error> {
40 let full_def: ProcessDefinition = serde_json::from_value(self.definition).map_err(|e| {
41 error!(
42 "Error while converting definition to process definition: {}",
43 e
44 );
45 CreateProcessError::FullDefinitionNotValid
46 })?;
47 let with_uuid = ProcessDefinition {
48 uuid: Some(self.uuid),
49 ..full_def
50 };
51 Ok(with_uuid)
52 }
53}