// file: kb_lib/src/db/dtos/launch_attribution.rs //! Launch attribution DTO. /// Application-facing launch attribution DTO. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct KbLaunchAttributionDto { /// Optional numeric primary key. pub id: std::option::Option, /// Related launch surface id. pub launch_surface_id: i64, /// Related transaction id. pub transaction_id: i64, /// Related decoded event id. pub decoded_event_id: i64, /// Optional related pool id. pub pool_id: std::option::Option, /// Optional related pair id. pub pair_id: std::option::Option, /// Optional related matched key id. pub matched_key_id: std::option::Option, /// Decoded protocol name. pub protocol_name: std::string::String, /// Match kind used for attribution. pub match_kind: std::string::String, /// Matched value used for attribution. pub matched_value: std::string::String, /// Attribution timestamp. pub attributed_at: chrono::DateTime, /// Update timestamp. pub updated_at: chrono::DateTime, } impl KbLaunchAttributionDto { /// Creates a new launch attribution DTO. pub fn new( launch_surface_id: i64, transaction_id: i64, decoded_event_id: i64, pool_id: std::option::Option, pair_id: std::option::Option, matched_key_id: std::option::Option, protocol_name: std::string::String, match_kind: std::string::String, matched_value: std::string::String, ) -> Self { let now = chrono::Utc::now(); Self { id: None, launch_surface_id, transaction_id, decoded_event_id, pool_id, pair_id, matched_key_id, protocol_name, match_kind, matched_value, attributed_at: now, updated_at: now, } } } impl TryFrom for KbLaunchAttributionDto { type Error = crate::KbError; fn try_from(entity: crate::KbLaunchAttributionEntity) -> Result { let attributed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.attributed_at); let attributed_at = match attributed_at_result { Ok(attributed_at) => attributed_at.with_timezone(&chrono::Utc), Err(error) => { return Err(crate::KbError::Db(format!( "cannot parse launch_attribution attributed_at '{}': {}", entity.attributed_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_attribution updated_at '{}': {}", entity.updated_at, error ))); } }; Ok(Self { id: Some(entity.id), launch_surface_id: entity.launch_surface_id, transaction_id: entity.transaction_id, decoded_event_id: entity.decoded_event_id, pool_id: entity.pool_id, pair_id: entity.pair_id, matched_key_id: entity.matched_key_id, protocol_name: entity.protocol_name, match_kind: entity.match_kind, matched_value: entity.matched_value, attributed_at, updated_at, }) } }