feat(domain): extend ChannelRepository and ScheduleRepository ports for history

This commit is contained in:
2026-03-17 14:25:51 +01:00
parent 995f5b1339
commit 1338f6bace

View File

@@ -10,7 +10,7 @@ use chrono::DateTime;
use chrono::Utc; use chrono::Utc;
use uuid::Uuid; use uuid::Uuid;
use crate::entities::{Channel, GeneratedSchedule, PlaybackRecord, User}; use crate::entities::{Channel, ChannelConfigSnapshot, GeneratedSchedule, PlaybackRecord, ScheduleConfig, User};
use crate::errors::DomainResult; use crate::errors::DomainResult;
use crate::value_objects::{BlockId, ChannelId, MediaItemId, UserId}; use crate::value_objects::{BlockId, ChannelId, MediaItemId, UserId};
@@ -71,6 +71,33 @@ pub trait ChannelRepository: Send + Sync {
/// Insert or update a channel. /// Insert or update a channel.
async fn save(&self, channel: &Channel) -> DomainResult<()>; async fn save(&self, channel: &Channel) -> DomainResult<()>;
async fn delete(&self, id: ChannelId) -> DomainResult<()>; async fn delete(&self, id: ChannelId) -> DomainResult<()>;
/// Snapshot the current config before saving a new one.
/// version_num is computed by the infra layer as MAX(version_num)+1 inside a transaction.
async fn save_config_snapshot(
&self,
channel_id: ChannelId,
config: &ScheduleConfig,
label: Option<String>,
) -> DomainResult<ChannelConfigSnapshot>;
async fn list_config_snapshots(
&self,
channel_id: ChannelId,
) -> DomainResult<Vec<ChannelConfigSnapshot>>;
async fn get_config_snapshot(
&self,
channel_id: ChannelId,
snapshot_id: Uuid,
) -> DomainResult<Option<ChannelConfigSnapshot>>;
async fn patch_config_snapshot_label(
&self,
channel_id: Uuid,
snapshot_id: Uuid,
label: Option<String>,
) -> DomainResult<Option<ChannelConfigSnapshot>>;
} }
/// Repository port for `GeneratedSchedule` and `PlaybackRecord` persistence. /// Repository port for `GeneratedSchedule` and `PlaybackRecord` persistence.
@@ -107,6 +134,28 @@ pub trait ScheduleRepository: Send + Sync {
&self, &self,
channel_id: ChannelId, channel_id: ChannelId,
) -> DomainResult<HashMap<BlockId, MediaItemId>>; ) -> DomainResult<HashMap<BlockId, MediaItemId>>;
/// List all generated schedule headers for a channel, newest first.
async fn list_schedule_history(
&self,
channel_id: ChannelId,
) -> DomainResult<Vec<GeneratedSchedule>>;
/// Fetch a specific schedule with its slots, verifying channel ownership.
async fn get_schedule_by_id(
&self,
channel_id: ChannelId,
schedule_id: Uuid,
) -> DomainResult<Option<GeneratedSchedule>>;
/// Delete all schedules with generation > target_generation for this channel.
/// Also deletes matching playback_records (no DB cascade between those tables).
/// scheduled_slots cascade via FK from generated_schedules.
async fn delete_schedules_after(
&self,
channel_id: ChannelId,
target_generation: u32,
) -> DomainResult<()>;
} }
/// Repository port for activity log persistence. /// Repository port for activity log persistence.