Files
k-tv/crates/application/src/channels/update.rs

56 lines
1.5 KiB
Rust

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<Channel> {
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.rotation_policy {
channel.set_rotation_policy(policy);
}
if let Some(auto) = cmd.auto_schedule {
channel.set_auto_schedule(auto);
}
if let Some(gap_filler) = cmd.gap_filler {
channel.set_gap_filler(gap_filler);
}
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;