use domain::events::DomainEvent; use domain::models::Channel; use domain::DomainResult; use super::commands::UpdateChannelCommand; use super::deps::ChannelCommandDeps; use super::find_owned_channel; pub async fn execute(deps: &ChannelCommandDeps, cmd: UpdateChannelCommand) -> DomainResult { let mut channel = find_owned_channel(deps.channel_query.as_ref(), cmd.channel_id, cmd.owner_id) .await?; if cmd.schedule_config.is_some() { deps.channel_command .save_config_snapshot(cmd.channel_id, channel.schedule_config(), None) .await?; } if let Some(name) = cmd.name { channel.set_name(name); } if let Some(description) = cmd.description { channel.set_description(description); } if let Some(timezone) = cmd.timezone { channel.set_timezone(timezone); } if let Some(config) = cmd.schedule_config { channel.set_schedule_config(config); } if let Some(policy) = cmd.recycle_policy { channel.set_recycle_policy(policy); } if let Some(auto) = cmd.auto_schedule { channel.set_auto_schedule(auto); } deps.channel_command.save(&channel).await?; deps.event_publisher .publish(DomainEvent::ChannelUpdated { channel_id: channel.id(), }) .await?; Ok(channel) } #[cfg(test)] #[path = "tests/update.rs"] mod tests;