Files
k-tv/crates/application/src/channels/update.rs
Gabriel Kaszewski c0e685a4ee refactor(domain): Row structs for from_persistence, ID newtypes, kill clippy.toml
- delete clippy.toml (too-many-arguments-threshold=20 hack)
- ChannelRow/MediaItemRow/LibraryItemRow structs for from_persistence
- SnapshotId/ActivityEventId/PlaybackRecordId newtypes
- DomainError variants use ChannelId/UserId instead of Uuid
- ActivityEvent.channel_id: Option<ChannelId> not Option<Uuid>
- InMemory repos key on newtype IDs
- AlgorithmicParams struct for schedule engine
- update all adapters/application/presentation callers
2026-07-12 05:00:49 +02:00

53 lines
1.4 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.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;