strip all comments, extract tests to tests/ dirs, remove #[allow(clippy::...)], extract magic numbers to constants, refactor schedule engine private methods to use param structs, add Default impls, clippy.toml for persistence constructors
56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use async_trait::async_trait;
|
|
use chrono::{DateTime, Utc};
|
|
use crate::errors::DomainResult;
|
|
use crate::models::{GeneratedSchedule, PlaybackRecord};
|
|
use crate::value_objects::{BlockId, ChannelId, MediaItemId, ScheduleId};
|
|
|
|
#[async_trait]
|
|
pub trait ScheduleCommand: Send + Sync {
|
|
async fn save(&self, schedule: &GeneratedSchedule) -> DomainResult<()>;
|
|
|
|
async fn save_playback_record(&self, record: &PlaybackRecord) -> DomainResult<()>;
|
|
|
|
async fn delete_schedules_after(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
target_generation: u32,
|
|
) -> DomainResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait ScheduleQuery: Send + Sync {
|
|
async fn find_active(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
at: DateTime<Utc>,
|
|
) -> DomainResult<Option<GeneratedSchedule>>;
|
|
|
|
async fn find_latest(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
) -> DomainResult<Option<GeneratedSchedule>>;
|
|
|
|
async fn find_playback_history(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
) -> DomainResult<Vec<PlaybackRecord>>;
|
|
|
|
async fn find_last_slot_per_block(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
) -> DomainResult<HashMap<BlockId, MediaItemId>>;
|
|
|
|
async fn list_schedule_history(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
) -> DomainResult<Vec<GeneratedSchedule>>;
|
|
|
|
async fn get_schedule_by_id(
|
|
&self,
|
|
channel_id: ChannelId,
|
|
schedule_id: ScheduleId,
|
|
) -> DomainResult<Option<GeneratedSchedule>>;
|
|
}
|