Files
k-tv/k-tv-backend/domain/src/repositories.rs
Gabriel Kaszewski 01108aa23e feat: initialize k-tv-frontend with Next.js and Tailwind CSS
- Added package.json with dependencies and scripts for development, build, and linting.
- Created postcss.config.mjs for Tailwind CSS integration.
- Added SVG assets for UI components including file, globe, next, vercel, and window icons.
- Configured TypeScript with tsconfig.json for strict type checking and module resolution.
2026-03-11 19:13:21 +01:00

72 lines
2.5 KiB
Rust

//! Repository ports (traits)
//!
//! These traits define the interface for data persistence.
//! Implementations live in the infra layer.
use async_trait::async_trait;
use chrono::DateTime;
use chrono::Utc;
use uuid::Uuid;
use crate::entities::{Channel, GeneratedSchedule, PlaybackRecord, User};
use crate::errors::DomainResult;
use crate::value_objects::{ChannelId, UserId};
/// Repository port for User persistence
#[async_trait]
pub trait UserRepository: Send + Sync {
/// Find a user by their internal ID
async fn find_by_id(&self, id: Uuid) -> DomainResult<Option<User>>;
/// Find a user by their OIDC subject (used for authentication)
async fn find_by_subject(&self, subject: &str) -> DomainResult<Option<User>>;
/// Find a user by their email
async fn find_by_email(&self, email: &str) -> DomainResult<Option<User>>;
/// Save a new user or update an existing one
async fn save(&self, user: &User) -> DomainResult<()>;
/// Delete a user by their ID
async fn delete(&self, id: Uuid) -> DomainResult<()>;
}
/// Repository port for `Channel` persistence.
#[async_trait]
pub trait ChannelRepository: Send + Sync {
async fn find_by_id(&self, id: ChannelId) -> DomainResult<Option<Channel>>;
async fn find_by_owner(&self, owner_id: UserId) -> DomainResult<Vec<Channel>>;
/// Insert or update a channel.
async fn save(&self, channel: &Channel) -> DomainResult<()>;
async fn delete(&self, id: ChannelId) -> DomainResult<()>;
}
/// Repository port for `GeneratedSchedule` and `PlaybackRecord` persistence.
#[async_trait]
pub trait ScheduleRepository: Send + Sync {
/// Find the schedule whose `[valid_from, valid_until)` window contains `at`.
async fn find_active(
&self,
channel_id: ChannelId,
at: DateTime<Utc>,
) -> DomainResult<Option<GeneratedSchedule>>;
/// Find the most recently generated schedule for a channel.
/// Used to derive the next generation number.
async fn find_latest(
&self,
channel_id: ChannelId,
) -> DomainResult<Option<GeneratedSchedule>>;
/// Insert or replace a generated schedule.
async fn save(&self, schedule: &GeneratedSchedule) -> DomainResult<()>;
/// All playback records for a channel, used by the recycle policy engine.
async fn find_playback_history(
&self,
channel_id: ChannelId,
) -> DomainResult<Vec<PlaybackRecord>>;
async fn save_playback_record(&self, record: &PlaybackRecord) -> DomainResult<()>;
}