feat(sonarr): Added the ability to fetch Sonarr logs
This commit is contained in:
@@ -3,8 +3,9 @@ use strum::EnumIter;
|
||||
|
||||
use crate::models::{
|
||||
sonarr_models::{BlocklistItem, Series},
|
||||
stateful_list::StatefulList,
|
||||
stateful_table::StatefulTable,
|
||||
Route,
|
||||
HorizontallyScrollableText, Route,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -16,6 +17,7 @@ pub struct SonarrData {
|
||||
pub start_time: DateTime<Utc>,
|
||||
pub series: StatefulTable<Series>,
|
||||
pub blocklist: StatefulTable<BlocklistItem>,
|
||||
pub logs: StatefulList<HorizontallyScrollableText>,
|
||||
}
|
||||
|
||||
impl Default for SonarrData {
|
||||
@@ -25,6 +27,7 @@ impl Default for SonarrData {
|
||||
start_time: DateTime::default(),
|
||||
series: StatefulTable::default(),
|
||||
blocklist: StatefulTable::default(),
|
||||
logs: StatefulList::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ mod tests {
|
||||
assert_eq!(sonarr_data.start_time, <DateTime<Utc>>::default());
|
||||
assert!(sonarr_data.series.is_empty());
|
||||
assert!(sonarr_data.blocklist.is_empty());
|
||||
assert!(sonarr_data.logs.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,23 @@ pub struct Language {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Log {
|
||||
pub time: DateTime<Utc>,
|
||||
pub exception: Option<String>,
|
||||
pub exception_type: Option<String>,
|
||||
pub level: String,
|
||||
pub logger: Option<String>,
|
||||
pub message: Option<String>,
|
||||
pub method: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct LogResponse {
|
||||
pub records: Vec<Log>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct Quality {
|
||||
pub name: String,
|
||||
@@ -215,6 +232,7 @@ pub enum SonarrSerdeable {
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
LogResponse(LogResponse),
|
||||
}
|
||||
|
||||
impl From<SonarrSerdeable> for Serdeable {
|
||||
@@ -235,6 +253,7 @@ serde_enum_from!(
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
LogResponse(LogResponse),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ mod tests {
|
||||
|
||||
use crate::models::{
|
||||
sonarr_models::{
|
||||
BlocklistItem, BlocklistResponse, Series, SeriesStatus, SeriesType, SonarrSerdeable,
|
||||
SystemStatus,
|
||||
BlocklistItem, BlocklistResponse, Log, LogResponse, Series, SeriesStatus, SeriesType,
|
||||
SonarrSerdeable, SystemStatus,
|
||||
},
|
||||
Serdeable,
|
||||
};
|
||||
@@ -109,4 +109,18 @@ mod tests {
|
||||
SonarrSerdeable::BlocklistResponse(blocklist_response)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from_log_response() {
|
||||
let log_response = LogResponse {
|
||||
records: vec![Log {
|
||||
level: "info".to_owned(),
|
||||
..Log::default()
|
||||
}],
|
||||
};
|
||||
|
||||
let sonarr_serdeable: SonarrSerdeable = log_response.clone().into();
|
||||
|
||||
assert_eq!(sonarr_serdeable, SonarrSerdeable::LogResponse(log_response));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user