some more tests and metadata
This commit is contained in:
59
src/metadata.rs
Normal file
59
src/metadata.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use serde::Serialize;
|
||||
use crate::response_deserializer::{
|
||||
Chapter, ContentRating, Language, Manga, PublicationDemographic, State, Status, Titles,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Metadata {
|
||||
title: String,
|
||||
original_language: Language,
|
||||
last_volume: f32,
|
||||
last_chapter: f32,
|
||||
publication_demographic: Option<PublicationDemographic>,
|
||||
status: Status,
|
||||
year: Option<u32>,
|
||||
content_rating: ContentRating,
|
||||
state: State,
|
||||
created_at: String,
|
||||
updated_at: String,
|
||||
chapters: Vec<ChapterMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
struct ChapterMetadata {
|
||||
chapter: f32,
|
||||
volume: f32,
|
||||
title: String,
|
||||
pages: u32,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
pub fn new(manga: Manga, chapters: Vec<Chapter>) -> Self {
|
||||
let attributes = manga.attributes;
|
||||
Self {
|
||||
title: attributes.title.en,
|
||||
original_language: attributes.original_language,
|
||||
last_volume: attributes.last_volume.unwrap(),
|
||||
last_chapter: attributes.last_chapter.unwrap(),
|
||||
publication_demographic: attributes.publication_demographic,
|
||||
status: attributes.status,
|
||||
year: attributes.year,
|
||||
content_rating: attributes.content_rating,
|
||||
state: attributes.state,
|
||||
created_at: attributes.created_at.to_string(),
|
||||
updated_at: attributes.updated_at.to_string(),
|
||||
chapters: chapters
|
||||
.iter()
|
||||
.map(|m| ChapterMetadata {
|
||||
chapter: m.attributes.chapter.unwrap(),
|
||||
volume: m.attributes.volume.unwrap(),
|
||||
title: m.attributes.title.clone(),
|
||||
pages: m.attributes.pages,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user