some more tests and metadata

This commit is contained in:
2025-07-09 18:43:34 +02:00
parent e797a8b8ae
commit 66daaad6a7
7 changed files with 140 additions and 29 deletions

59
src/metadata.rs Normal file
View 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(),
}
}
}