Add endpoint to get information for a theme

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 3 years ago
parent 7725daa2bb
commit 2181d1d7b4
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,6 @@
use crate::error::ApiResult;
use crate::models::{
Anime, AnimeSynonym, Artist, Image, Resource, SearchResponse, Series, Song, ThemeEntry,
Anime, AnimeSynonym, Artist, Image, Resource, SearchResponse, Series, Song, Theme, ThemeEntry,
};
use reqwest::Response;
use serde::de::DeserializeOwned;
@ -112,6 +112,11 @@ impl AnimeThemesClient {
self.entry_by_id_with_include("synonym", id, include).await
}
/// Returns a theme by id
pub async fn theme(&self, id: u32, include: &[&str]) -> ApiResult<Theme> {
self.entry_by_id_with_include("theme", id, include).await
}
/// Generic endpoint with the format /<endpoint>/<id> returning the type on the json field <endpoint>
async fn entry_by_id_with_include<T: DeserializeOwned, I: Display>(
&self,

@ -50,6 +50,8 @@ pub struct Theme {
pub group: String,
pub slug: String,
pub song: Option<Song>,
pub anime: Option<Anime>,
pub entries: Option<Vec<ThemeEntry>>,
}
#[derive(Debug, Clone, Deserialize)]

@ -83,3 +83,11 @@ async fn it_returns_songs_by_id() {
assert!(result.themes.is_some())
}
#[tokio::test]
async fn it_returns_themes_by_id() {
let client = AnimeThemesClient::default();
let result = client.theme(8187, &["entries"]).await.unwrap();
assert!(result.entries.is_some())
}

Loading…
Cancel
Save