application: config_snapshots, admin, providers, iptv

This commit is contained in:
2026-07-12 02:14:07 +02:00
parent ebf0614fdf
commit 466d34b5d0
37 changed files with 895 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
use domain::models::Channel;
use domain::value_objects::ChannelId;
use domain::{DomainError, DomainResult};
use super::commands::RestoreSnapshotCommand;
use super::deps::ConfigSnapshotDeps;
/// Restore a channel's config from a snapshot.
///
/// Flow: find snapshot -> find channel -> snapshot current config (backup) ->
/// apply snapshot config to channel -> save channel -> return updated channel.
pub async fn execute(
deps: &ConfigSnapshotDeps,
cmd: RestoreSnapshotCommand,
) -> DomainResult<Channel> {
let channel_id = ChannelId::from(cmd.channel_id);
let snapshot = deps
.channel_query
.get_config_snapshot(channel_id, cmd.snapshot_id)
.await?
.ok_or(DomainError::ValidationError(format!(
"Snapshot {} not found",
cmd.snapshot_id
)))?;
let mut channel = deps
.channel_query
.find_by_id(channel_id)
.await?
.ok_or(DomainError::ChannelNotFound(cmd.channel_id))?;
// Auto-snapshot the current config before overwriting
deps.channel_command
.save_config_snapshot(channel_id, channel.schedule_config(), None)
.await?;
// Apply the snapshot's config
channel.set_schedule_config(snapshot.config().clone());
deps.channel_command.save(&channel).await?;
Ok(channel)
}