From eff14228aff8dafa77418392ceafaa196eb9d0ac Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 12 Jul 2026 04:12:51 +0200 Subject: [PATCH] refactor(api-types): strip comments, extract DEFAULT_ACCESS_MODE constant --- crates/api-types/src/admin.rs | 4 ---- crates/api-types/src/auth.rs | 8 -------- crates/api-types/src/channels.rs | 23 ----------------------- crates/api-types/src/common.rs | 8 -------- crates/api-types/src/config.rs | 11 ----------- crates/api-types/src/lib.rs | 14 +++----------- crates/api-types/src/library.rs | 7 ------- crates/api-types/src/providers.rs | 7 ------- crates/api-types/src/schedule.rs | 23 ++++------------------- crates/api-types/src/transcode.rs | 5 ----- 10 files changed, 7 insertions(+), 103 deletions(-) diff --git a/crates/api-types/src/admin.rs b/crates/api-types/src/admin.rs index f974943..e06d314 100644 --- a/crates/api-types/src/admin.rs +++ b/crates/api-types/src/admin.rs @@ -1,17 +1,13 @@ -//! Admin response DTOs. - use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use uuid::Uuid; -/// Admin settings response (key-value pairs from `app_settings` table). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct SettingsResponse { pub settings: std::collections::HashMap, } -/// An activity log entry for the admin dashboard. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ActivityEventResponse { pub id: Uuid, diff --git a/crates/api-types/src/auth.rs b/crates/api-types/src/auth.rs index 2fb35b4..86472f9 100644 --- a/crates/api-types/src/auth.rs +++ b/crates/api-types/src/auth.rs @@ -1,11 +1,8 @@ -//! Authentication request and response DTOs. - use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use uuid::Uuid; -/// Login request. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct LoginRequest { pub email: String, @@ -14,31 +11,26 @@ pub struct LoginRequest { pub remember_me: bool, } -/// Register request. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct RegisterRequest { pub email: String, pub password: String, } -/// Refresh token request. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct RefreshRequest { pub refresh_token: String, } -/// JWT token response. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct TokenResponse { pub access_token: String, pub token_type: String, pub expires_in: u64, - /// Only present when `remember_me` was true at login, or on token refresh. #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, } -/// User response DTO. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct UserResponse { pub id: Uuid, diff --git a/crates/api-types/src/channels.rs b/crates/api-types/src/channels.rs index fcabb07..e375069 100644 --- a/crates/api-types/src/channels.rs +++ b/crates/api-types/src/channels.rs @@ -1,5 +1,3 @@ -//! Channel request and response DTOs. - use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; @@ -7,16 +5,12 @@ use uuid::Uuid; use crate::common::enum_to_string; -/// Create channel request. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CreateChannelRequest { pub name: String, pub description: Option, - /// IANA timezone, e.g. "UTC" or "America/New_York". pub timezone: String, - /// One of: "public", "password_protected", "account_required", "owner_only". pub access_mode: Option, - /// Plain-text password; hashed before storage. pub access_password: Option, pub webhook_url: Option, pub webhook_poll_interval_secs: Option, @@ -24,36 +18,25 @@ pub struct CreateChannelRequest { pub webhook_headers: Option, } -/// Update channel request. All fields are optional -- only provided fields are -/// updated. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct UpdateChannelRequest { pub name: Option, pub description: Option, pub timezone: Option, - /// Replace the entire schedule config (template import/edit). pub schedule_config: Option, pub recycle_policy: Option, pub auto_schedule: Option, - /// One of: "public", "password_protected", "account_required", "owner_only". pub access_mode: Option, - /// Empty string clears the password; non-empty re-hashes. pub access_password: Option, - /// `null` = clear logo, string = set logo URL. Omit to leave unchanged. pub logo: Option>, - /// One of: "top_left", "top_right", "bottom_left", "bottom_right". pub logo_position: Option, pub logo_opacity: Option, - /// `null` = clear, string = set. Omit to leave unchanged. pub webhook_url: Option>, pub webhook_poll_interval_secs: Option, - /// `null` = clear, string = set. Omit to leave unchanged. pub webhook_body_template: Option>, - /// `null` = clear, string = set. Omit to leave unchanged. pub webhook_headers: Option>, } -/// Channel response DTO. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ChannelResponse { pub id: Uuid, @@ -61,15 +44,11 @@ pub struct ChannelResponse { pub name: String, pub description: Option, pub timezone: String, - /// The full schedule config as a JSON object, decoupled from domain internals. pub schedule_config: serde_json::Value, - /// The recycle policy as a JSON object. pub recycle_policy: serde_json::Value, pub auto_schedule: bool, - /// E.g. "public", "password_protected", "account_required", "owner_only". pub access_mode: String, pub logo: Option, - /// E.g. "top_left", "top_right", "bottom_left", "bottom_right". pub logo_position: String, pub logo_opacity: f32, pub webhook_url: Option, @@ -105,7 +84,6 @@ impl From for ChannelResponse { } } -/// Config history snapshot response. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ConfigSnapshotResponse { pub id: Uuid, @@ -125,7 +103,6 @@ impl From for ConfigSnapshotResponse { } } -/// Patch snapshot request (rename label). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PatchSnapshotRequest { pub label: Option, diff --git a/crates/api-types/src/common.rs b/crates/api-types/src/common.rs index 203c9ed..575f379 100644 --- a/crates/api-types/src/common.rs +++ b/crates/api-types/src/common.rs @@ -1,9 +1,6 @@ -//! Common types shared across API modules. - use serde::{Deserialize, Serialize}; use utoipa::ToSchema; -/// Paginated response wrapper. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PaginatedResponse { pub items: Vec, @@ -16,7 +13,6 @@ impl PaginatedResponse { } } -/// Standard error response body. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ErrorResponse { pub error: String, @@ -40,10 +36,6 @@ impl ErrorResponse { } } -/// Serialize a `serde::Serialize` enum to its snake_case string representation. -/// -/// Used internally by `From` impls to convert domain enums (AccessMode, -/// LogoPosition, ContentType, etc.) into plain strings for API responses. pub(crate) fn enum_to_string(val: &T) -> String { serde_json::to_value(val) .ok() diff --git a/crates/api-types/src/config.rs b/crates/api-types/src/config.rs index db699ac..165472c 100644 --- a/crates/api-types/src/config.rs +++ b/crates/api-types/src/config.rs @@ -1,11 +1,8 @@ -//! System configuration response DTOs. - use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::common::enum_to_string; -/// Provider capabilities response, mirroring the domain type for OpenAPI docs. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ProviderCapabilitiesResponse { pub collections: bool, @@ -14,11 +11,8 @@ pub struct ProviderCapabilitiesResponse { pub tags: bool, pub decade: bool, pub search: bool, - /// E.g. "hls" or "direct_file". pub streaming_protocol: String, - /// Whether `POST /files/rescan` is available. pub rescan: bool, - /// Whether on-demand FFmpeg transcoding to HLS is available. pub transcode: bool, } @@ -38,21 +32,16 @@ impl From for ProviderCapabilitiesResponse } } -/// Per-provider info returned in the system config response. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ProviderInfo { pub id: String, pub capabilities: ProviderCapabilitiesResponse, } -/// System configuration response (`GET /config`). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ConfigResponse { pub allow_registration: bool, - /// All registered providers with their capabilities. pub providers: Vec, - /// Capabilities of the primary provider -- kept for backward compatibility. pub provider_capabilities: ProviderCapabilitiesResponse, - /// Provider type strings supported by this build (feature-gated). pub available_provider_types: Vec, } diff --git a/crates/api-types/src/lib.rs b/crates/api-types/src/lib.rs index 7ca000c..0b03f9a 100644 --- a/crates/api-types/src/lib.rs +++ b/crates/api-types/src/lib.rs @@ -1,12 +1,3 @@ -//! HTTP request and response DTOs with OpenAPI schema generation. -//! -//! Pure data transfer objects for the API layer. All structs derive -//! `Serialize`, `Deserialize`, and `utoipa::ToSchema` for automatic -//! OpenAPI documentation. -//! -//! Response types provide `From` implementations to -//! convert domain models into API-facing DTOs. - pub mod admin; pub mod auth; pub mod channels; @@ -17,7 +8,6 @@ pub mod providers; pub mod schedule; pub mod transcode; -// Re-export all public types for convenience. pub use admin::{ActivityEventResponse, SettingsResponse}; pub use auth::{LoginRequest, RefreshRequest, RegisterRequest, TokenResponse, UserResponse}; pub use channels::{ @@ -32,4 +22,6 @@ pub use schedule::{ CurrentBroadcastResponse, MediaItemResponse, ScheduleHistoryEntry, ScheduleResponse, SlotResponse, }; -pub use transcode::{TranscodeSettingsResponse, TranscodeStatsResponse, UpdateTranscodeSettingsRequest}; +pub use transcode::{ + TranscodeSettingsResponse, TranscodeStatsResponse, UpdateTranscodeSettingsRequest, +}; diff --git a/crates/api-types/src/library.rs b/crates/api-types/src/library.rs index 22f9697..03bdb9b 100644 --- a/crates/api-types/src/library.rs +++ b/crates/api-types/src/library.rs @@ -1,18 +1,14 @@ -//! Library browsing response DTOs. - use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::common::enum_to_string; -/// Library item response (synced from a media provider). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct LibraryItemResponse { pub id: String, pub provider_id: String, pub external_id: String, pub title: String, - /// E.g. "movie", "episode", "short". pub content_type: String, pub duration_secs: u32, pub series_name: Option, @@ -52,7 +48,6 @@ impl From for LibraryItemResponse { } } -/// Library collection summary. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CollectionResponse { pub id: String, @@ -70,7 +65,6 @@ impl From for CollectionResponse { } } -/// TV show summary aggregated from synced episodes. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ShowResponse { pub series_name: String, @@ -92,7 +86,6 @@ impl From for ShowResponse { } } -/// Season summary within a TV show. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct SeasonResponse { pub season_number: u32, diff --git a/crates/api-types/src/providers.rs b/crates/api-types/src/providers.rs index ebe69e3..f0f163a 100644 --- a/crates/api-types/src/providers.rs +++ b/crates/api-types/src/providers.rs @@ -1,14 +1,9 @@ -//! Provider configuration request and response DTOs. - use serde::{Deserialize, Serialize}; use utoipa::ToSchema; -/// Request to create or update a provider configuration. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ProviderConfigRequest { - /// E.g. "jellyfin", "local_files". pub provider_type: String, - /// Provider-specific configuration blob (URL, API key, path, etc.). pub config: serde_json::Value, #[serde(default = "default_true")] pub enabled: bool, @@ -18,12 +13,10 @@ fn default_true() -> bool { true } -/// Provider configuration response. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ProviderConfigResponse { pub id: String, pub provider_type: String, - /// Provider-specific configuration blob (deserialized from stored JSON). pub config: serde_json::Value, pub enabled: bool, pub updated_at: String, diff --git a/crates/api-types/src/schedule.rs b/crates/api-types/src/schedule.rs index 472d09d..5f03628 100644 --- a/crates/api-types/src/schedule.rs +++ b/crates/api-types/src/schedule.rs @@ -1,5 +1,3 @@ -//! Schedule and EPG response DTOs. - use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; @@ -7,12 +5,12 @@ use uuid::Uuid; use crate::common::enum_to_string; -/// Media item snapshot within a scheduled slot. +const DEFAULT_ACCESS_MODE: &str = "public"; + #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct MediaItemResponse { pub id: String, pub title: String, - /// E.g. "movie", "episode", "short". pub content_type: String, pub duration_secs: u32, pub description: Option, @@ -42,7 +40,6 @@ impl From for MediaItemResponse { } } -/// A single resolved broadcast slot within a schedule. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct SlotResponse { pub id: Uuid, @@ -50,7 +47,6 @@ pub struct SlotResponse { pub end_at: DateTime, pub item: MediaItemResponse, pub source_block_id: Uuid, - /// Access mode of the programming block that produced this slot. #[serde(default)] pub block_access_mode: String, } @@ -63,21 +59,19 @@ impl From for SlotResponse { end_at: s.end_at(), item: s.item().clone().into(), source_block_id: s.source_block_id().value(), - block_access_mode: String::from("public"), + block_access_mode: String::from(DEFAULT_ACCESS_MODE), } } } impl SlotResponse { - /// Build a slot response with the block-level access mode resolved from the - /// channel's schedule config. pub fn with_block_access(slot: domain::ScheduledSlot, channel: &domain::Channel) -> Self { let block_access_mode = channel .schedule_config() .all_blocks() .find(|b| b.id() == slot.source_block_id()) .map(|b| enum_to_string(b.access_mode())) - .unwrap_or_else(|| String::from("public")); + .unwrap_or_else(|| String::from(DEFAULT_ACCESS_MODE)); Self { id: slot.id().value(), start_at: slot.start_at(), @@ -89,21 +83,13 @@ impl SlotResponse { } } -/// What is currently playing on a channel. -/// -/// A 204 No Content response is returned instead when there is no active slot -/// (no-signal / dead air). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CurrentBroadcastResponse { pub slot: SlotResponse, - /// Seconds elapsed since the start of the current item -- use as the - /// initial seek position for the player. pub offset_secs: u32, - /// Access mode of the block currently playing. The stream is gated by this. pub block_access_mode: String, } -/// Full schedule response with all resolved slots. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ScheduleResponse { pub id: Uuid, @@ -133,7 +119,6 @@ impl From for ScheduleResponse { } } -/// Compact schedule history entry (no slots, just metadata). #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ScheduleHistoryEntry { pub id: Uuid, diff --git a/crates/api-types/src/transcode.rs b/crates/api-types/src/transcode.rs index 4da14de..2d57e2e 100644 --- a/crates/api-types/src/transcode.rs +++ b/crates/api-types/src/transcode.rs @@ -1,21 +1,16 @@ -//! Transcode settings and stats response DTOs. - use serde::{Deserialize, Serialize}; use utoipa::ToSchema; -/// Transcode settings response. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct TranscodeSettingsResponse { pub cleanup_ttl_hours: u32, } -/// Request to update transcode settings. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct UpdateTranscodeSettingsRequest { pub cleanup_ttl_hours: u32, } -/// Transcode cache statistics. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct TranscodeStatsResponse { pub cache_size_bytes: u64,