// file: kb_lib/src/db/dtos/launch_surface_key.rs //! Launch surface key DTO. /// Application-facing launch surface key DTO. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct KbLaunchSurfaceKeyDto { /// Optional numeric primary key. pub id: std::option::Option, /// Related launch surface id. pub launch_surface_id: i64, /// Stable key kind. pub match_kind: std::string::String, /// Stable key value. pub match_value: std::string::String, /// Creation timestamp. pub created_at: chrono::DateTime, /// Update timestamp. pub updated_at: chrono::DateTime, } impl KbLaunchSurfaceKeyDto { /// Creates a new launch surface key DTO. pub fn new( launch_surface_id: i64, match_kind: std::string::String, match_value: std::string::String, ) -> Self { let now = chrono::Utc::now(); Self { id: None, launch_surface_id, match_kind, match_value, created_at: now, updated_at: now, } } } impl TryFrom for KbLaunchSurfaceKeyDto { type Error = crate::KbError; fn try_from(entity: crate::KbLaunchSurfaceKeyEntity) -> Result { let created_at_result = chrono::DateTime::parse_from_rfc3339(&entity.created_at); let created_at = match created_at_result { Ok(created_at) => created_at.with_timezone(&chrono::Utc), Err(error) => { return Err(crate::KbError::Db(format!( "cannot parse launch_surface_key created_at '{}': {}", entity.created_at, error ))); } }; let updated_at_result = chrono::DateTime::parse_from_rfc3339(&entity.updated_at); let updated_at = match updated_at_result { Ok(updated_at) => updated_at.with_timezone(&chrono::Utc), Err(error) => { return Err(crate::KbError::Db(format!( "cannot parse launch_surface_key updated_at '{}': {}", entity.updated_at, error ))); } }; Ok(Self { id: Some(entity.id), launch_surface_id: entity.launch_surface_id, match_kind: entity.match_kind, match_value: entity.match_value, created_at, updated_at, }) } }