feat(sonarr): Added blocklist commands (List, Clear, Delete)
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use strum::EnumIter;
|
||||
|
||||
use crate::models::{sonarr_models::Series, stateful_table::StatefulTable, Route};
|
||||
use crate::models::{
|
||||
sonarr_models::{BlocklistItem, Series},
|
||||
stateful_table::StatefulTable,
|
||||
Route,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sonarr_data_tests.rs"]
|
||||
@@ -11,6 +15,7 @@ pub struct SonarrData {
|
||||
pub version: String,
|
||||
pub start_time: DateTime<Utc>,
|
||||
pub series: StatefulTable<Series>,
|
||||
pub blocklist: StatefulTable<BlocklistItem>,
|
||||
}
|
||||
|
||||
impl Default for SonarrData {
|
||||
@@ -19,12 +24,15 @@ impl Default for SonarrData {
|
||||
version: String::new(),
|
||||
start_time: DateTime::default(),
|
||||
series: StatefulTable::default(),
|
||||
blocklist: StatefulTable::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, EnumIter)]
|
||||
pub enum ActiveSonarrBlock {
|
||||
Blocklist,
|
||||
BlocklistSortPrompt,
|
||||
#[default]
|
||||
Series,
|
||||
SeriesSortPrompt,
|
||||
|
||||
@@ -37,6 +37,7 @@ mod tests {
|
||||
assert!(sonarr_data.version.is_empty());
|
||||
assert_eq!(sonarr_data.start_time, <DateTime<Utc>>::default());
|
||||
assert!(sonarr_data.series.is_empty());
|
||||
assert!(sonarr_data.blocklist.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,43 @@ use super::{HorizontallyScrollableText, Serdeable};
|
||||
#[path = "sonarr_models_tests.rs"]
|
||||
mod sonarr_models_tests;
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BlocklistItem {
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub id: i64,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub series_id: i64,
|
||||
pub episode_ids: Vec<Number>,
|
||||
pub source_title: String,
|
||||
pub language: Language,
|
||||
pub quality: QualityWrapper,
|
||||
pub date: DateTime<Utc>,
|
||||
pub protocol: String,
|
||||
pub indexer: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct BlocklistResponse {
|
||||
pub records: Vec<BlocklistItem>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct Language {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct Quality {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct QualityWrapper {
|
||||
pub quality: Quality,
|
||||
}
|
||||
|
||||
#[derive(Derivative, Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
#[derivative(Default)]
|
||||
pub struct Rating {
|
||||
@@ -177,6 +214,7 @@ pub enum SonarrSerdeable {
|
||||
Value(Value),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
}
|
||||
|
||||
impl From<SonarrSerdeable> for Serdeable {
|
||||
@@ -196,6 +234,7 @@ serde_enum_from!(
|
||||
Value(Value),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use crate::models::{
|
||||
sonarr_models::{Series, SeriesStatus, SeriesType, SonarrSerdeable, SystemStatus},
|
||||
sonarr_models::{
|
||||
BlocklistItem, BlocklistResponse, Series, SeriesStatus, SeriesType, SonarrSerdeable,
|
||||
SystemStatus,
|
||||
},
|
||||
Serdeable,
|
||||
};
|
||||
|
||||
@@ -89,4 +92,21 @@ mod tests {
|
||||
SonarrSerdeable::SystemStatus(system_status)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from_blocklist_response() {
|
||||
let blocklist_response = BlocklistResponse {
|
||||
records: vec![BlocklistItem {
|
||||
id: 1,
|
||||
..BlocklistItem::default()
|
||||
}],
|
||||
};
|
||||
|
||||
let sonarr_serdeable: SonarrSerdeable = blocklist_response.clone().into();
|
||||
|
||||
assert_eq!(
|
||||
sonarr_serdeable,
|
||||
SonarrSerdeable::BlocklistResponse(blocklist_response)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user