-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add show crew information in series page (#139)
- Loading branch information
1 parent
bca51c9
commit 3300cb8
Showing
14 changed files
with
638 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use serde::Deserialize; | ||
|
||
pub use super::AgeError; | ||
use crate::core::api::tv_maze::{get_pretty_json_from_url, ApiError, Image}; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Cast { | ||
pub person: super::Person, | ||
pub character: Character, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Character { | ||
pub name: String, | ||
pub image: Option<Image>, | ||
} | ||
|
||
// replace ID with the actual show id | ||
const SHOW_CAST_ADDRESS: &str = "https://api.tvmaze.com/shows/ID/cast"; | ||
|
||
pub async fn get_show_cast(series_id: u32) -> Result<String, ApiError> { | ||
let url = SHOW_CAST_ADDRESS.replace("ID", &series_id.to_string()); | ||
|
||
get_pretty_json_from_url(url) | ||
.await | ||
.map_err(ApiError::Network) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::Deserialize; | ||
|
||
pub use super::AgeError; | ||
use crate::core::api::tv_maze::{get_pretty_json_from_url, ApiError}; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Crew { | ||
#[serde(rename = "type")] | ||
pub kind: String, | ||
pub person: super::Person, | ||
} | ||
|
||
// replace ID with the actual show id | ||
const SHOW_CREW_ADDRESS: &str = "https://api.tvmaze.com/shows/ID/crew"; | ||
|
||
pub async fn get_show_crew(series_id: u32) -> Result<String, ApiError> { | ||
let url = SHOW_CREW_ADDRESS.replace("ID", &series_id.to_string()); | ||
|
||
get_pretty_json_from_url(url) | ||
.await | ||
.map_err(ApiError::Network) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::io::ErrorKind; | ||
|
||
use tracing::info; | ||
|
||
use super::{CacheFilePath, CACHER}; | ||
use crate::core::api::tv_maze::deserialize_json; | ||
use crate::core::api::tv_maze::people::show_cast::{self, Cast}; | ||
use crate::core::api::tv_maze::people::show_crew::{self, Crew}; | ||
use crate::core::api::tv_maze::ApiError; | ||
use crate::core::caching::{read_cache, write_cache}; | ||
|
||
pub async fn get_show_cast(series_id: u32) -> Result<Vec<Cast>, ApiError> { | ||
let series_cast_filepath = CACHER.get_cache_file_path(CacheFilePath::SeriesShowCast(series_id)); | ||
|
||
let json_string = match read_cache(&series_cast_filepath).await { | ||
Ok(json_string) => json_string, | ||
Err(err) => { | ||
info!("falling back online for 'show cast' for series id: {series_id}"); | ||
let json_string = show_cast::get_show_cast(series_id).await?; | ||
if err.kind() == ErrorKind::NotFound { | ||
write_cache(&json_string, &series_cast_filepath).await; | ||
} | ||
json_string | ||
} | ||
}; | ||
deserialize_json(&json_string) | ||
} | ||
|
||
pub async fn get_show_crew(series_id: u32) -> Result<Vec<Crew>, ApiError> { | ||
let series_crew_filepath = CACHER.get_cache_file_path(CacheFilePath::SeriesShowCrew(series_id)); | ||
|
||
let json_string = match read_cache(&series_crew_filepath).await { | ||
Ok(json_string) => json_string, | ||
Err(err) => { | ||
info!("falling back online for 'show crew' for series id: {series_id}"); | ||
let json_string = show_crew::get_show_crew(series_id).await?; | ||
if err.kind() == ErrorKind::NotFound { | ||
write_cache(&json_string, &series_crew_filepath).await; | ||
} | ||
json_string | ||
} | ||
}; | ||
deserialize_json(&json_string) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.