feat(models): Added the Episode model to Sonarr models
This commit is contained in:
@@ -2,9 +2,10 @@ use chrono::{DateTime, Utc};
|
||||
use strum::EnumIter;
|
||||
|
||||
use crate::models::{
|
||||
sonarr_models::{BlocklistItem, Series},
|
||||
sonarr_models::{BlocklistItem, Episode, Series},
|
||||
stateful_list::StatefulList,
|
||||
stateful_table::StatefulTable,
|
||||
stateful_tree::StatefulTree,
|
||||
HorizontallyScrollableText, Route,
|
||||
};
|
||||
|
||||
@@ -18,6 +19,7 @@ pub struct SonarrData {
|
||||
pub series: StatefulTable<Series>,
|
||||
pub blocklist: StatefulTable<BlocklistItem>,
|
||||
pub logs: StatefulList<HorizontallyScrollableText>,
|
||||
pub episodes: StatefulTree<Episode>,
|
||||
}
|
||||
|
||||
impl Default for SonarrData {
|
||||
@@ -28,6 +30,7 @@ impl Default for SonarrData {
|
||||
series: StatefulTable::default(),
|
||||
blocklist: StatefulTable::default(),
|
||||
logs: StatefulList::default(),
|
||||
episodes: StatefulTree::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,34 @@ pub struct BlocklistResponse {
|
||||
pub records: Vec<BlocklistItem>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Hash, Debug, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Episode {
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub id: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub series_id: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub tvdb_id: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub episode_file_id: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub season_number: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub episode_number: i64,
|
||||
pub title: Option<String>,
|
||||
pub air_date_utc: Option<DateTime<Utc>>,
|
||||
pub overview: Option<String>,
|
||||
pub has_file: bool,
|
||||
pub monitored: bool,
|
||||
}
|
||||
|
||||
impl Display for Episode {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.title.as_ref().unwrap_or(&String::new()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct Language {
|
||||
pub name: String,
|
||||
@@ -229,6 +257,7 @@ impl SeriesStatus {
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum SonarrSerdeable {
|
||||
Value(Value),
|
||||
Episodes(Vec<Episode>),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
@@ -250,6 +279,7 @@ impl From<()> for SonarrSerdeable {
|
||||
serde_enum_from!(
|
||||
SonarrSerdeable {
|
||||
Value(Value),
|
||||
Episodes(Vec<Episode>),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
|
||||
@@ -5,12 +5,23 @@ mod tests {
|
||||
|
||||
use crate::models::{
|
||||
sonarr_models::{
|
||||
BlocklistItem, BlocklistResponse, Log, LogResponse, Series, SeriesStatus, SeriesType,
|
||||
SonarrSerdeable, SystemStatus,
|
||||
BlocklistItem, BlocklistResponse, Episode, Log, LogResponse, Series, SeriesStatus,
|
||||
SeriesType, SonarrSerdeable, SystemStatus,
|
||||
},
|
||||
Serdeable,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_episode_display() {
|
||||
let episode = Episode {
|
||||
title: Some("Test Title".to_owned()),
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
assert_str_eq!(Episode::default().to_string(), "");
|
||||
assert_str_eq!(episode.to_string(), "Test Title");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_series_status_display() {
|
||||
assert_str_eq!(SeriesStatus::Continuing.to_string(), "continuing");
|
||||
@@ -66,6 +77,18 @@ mod tests {
|
||||
assert_eq!(sonarr_serdeable, SonarrSerdeable::Value(value));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from_episodes() {
|
||||
let episodes = vec![Episode {
|
||||
id: 1,
|
||||
..Episode::default()
|
||||
}];
|
||||
|
||||
let sonarr_serdeable: SonarrSerdeable = episodes.clone().into();
|
||||
|
||||
assert_eq!(sonarr_serdeable, SonarrSerdeable::Episodes(episodes));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from_series() {
|
||||
let series = vec![Series {
|
||||
|
||||
Reference in New Issue
Block a user