Repository: juspay/hyperswitch
File: crates/diesel_models/src/user/theme.rs (Rust)

Code before:
            theme_config_version,
        }
    }
}

impl Theme {
    pub fn email_config(&self) -> EmailThemeConfig {
        EmailThemeConfig {
            primary_color: self.email_primary_color.clone(),
            foreground_color: self.email_foreground_color.clone(),
            background_color: self.email_background_color.clone(),
            entity_name: self.email_entity_name.clone(),
            entity_logo_url: self.email_entity_logo_url.clone(),
        }
    }
}

#[derive(Clone, Debug, Default, AsChangeset, DebugAsDisplay)]
#[diesel(table_name = themes)]
pub struct ThemeUpdateInternal {
    pub email_primary_color: Option<String>,
    pub email_foreground_color: Option<String>,
    pub email_background_color: Option<String>,
    pub email_entity_name: Option<String>,
    pub email_entity_logo_url: Option<String>,
    pub last_modified_at: Option<PrimitiveDateTime>,
    pub theme_config_version: Option<String>,
}

#[derive(Clone)]
pub enum ThemeUpdate {
    EmailConfig { email_config: EmailThemeConfig },
    ThemeConfig,
}

impl From<ThemeUpdate> for ThemeUpdateInternal {
    fn from(value: ThemeUpdate) -> Self {
        let now = date_time::now();
        let theme_config_version = now.assume_utc().unix_timestamp().to_string();
        match value {
            ThemeUpdate::EmailConfig { email_config } => Self {
                email_primary_color: Some(email_config.primary_color),
                email_foreground_color: Some(email_config.foreground_color),
                email_background_color: Some(email_config.background_color),
                email_entity_name: Some(email_config.entity_name),
                email_entity_logo_url: Some(email_config.entity_logo_url),
                last_modified_at: Some(now),
                theme_config_version: None,
            },
            ThemeUpdate::ThemeConfig => Self {
                email_primary_color: None,

Review comment (suggestion):
Nit: Make this a required field, that way you can ensure that all updates to the record in the table would enforce us to update the `last_modified_at` value.

Code after:
            theme_config_version,
        }
    }
}

impl Theme {
    pub fn email_config(&self) -> EmailThemeConfig {
        EmailThemeConfig {
            primary_color: self.email_primary_color.clone(),
            foreground_color: self.email_foreground_color.clone(),
            background_color: self.email_background_color.clone(),
            entity_name: self.email_entity_name.clone(),
            entity_logo_url: self.email_entity_logo_url.clone(),
        }
    }
}

#[derive(Clone, Debug, AsChangeset, DebugAsDisplay)]
#[diesel(table_name = themes)]
pub struct ThemeUpdateInternal {
    pub email_primary_color: Option<String>,
    pub email_foreground_color: Option<String>,
    pub email_background_color: Option<String>,
    pub email_entity_name: Option<String>,
    pub email_entity_logo_url: Option<String>,
    pub last_modified_at: PrimitiveDateTime,
    pub theme_config_version: Option<String>,
}

#[derive(Clone)]
pub enum ThemeUpdate {
    EmailConfig { email_config: EmailThemeConfig },
    ThemeConfig,
}

impl From<ThemeUpdate> for ThemeUpdateInternal {
    fn from(value: ThemeUpdate) -> Self {
        let now = date_time::now();
        let theme_config_version = now.assume_utc().unix_timestamp().to_string();
        match value {
            ThemeUpdate::EmailConfig { email_config } => Self {
                email_primary_color: Some(email_config.primary_color),
                email_foreground_color: Some(email_config.foreground_color),
                email_background_color: Some(email_config.background_color),
                email_entity_name: Some(email_config.entity_name),
                email_entity_logo_url: Some(email_config.entity_logo_url),
                last_modified_at: now,
                theme_config_version: None,
            },
            ThemeUpdate::ThemeConfig => Self {
                email_primary_color: None,