mangadex_api_schema_rust/v5/
manga_aggregate.rs1#[cfg(feature = "serialize")]
2use std::collections::HashMap;
3
4use mangadex_api_types::ResultType;
5#[cfg(feature = "serialize")]
6use serde::Serialize;
7
8use serde::Deserialize;
9use uuid::Uuid;
10
11use crate::v5::{chapter_aggregate_array_or_map, volume_aggregate_array_or_map};
12
13#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
15#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
16pub struct MangaAggregate {
17 #[serde(default)]
18 pub result: ResultType,
19 #[serde(with = "volume_aggregate_array_or_map")]
21 pub volumes: Vec<VolumeAggregate>,
22}
23
24#[cfg(feature = "specta")]
25impl specta::Type for MangaAggregate {
26 fn inline(
27 opts: specta::DefOpts,
28 generics: &[specta::DataType],
29 ) -> Result<specta::DataType, specta::ExportError> {
30 MangaAggregatSer::inline(opts, generics)
31 }
32}
33
34#[cfg(feature = "serialize")]
35impl From<MangaAggregate> for MangaAggregatSer {
36 fn from(value: MangaAggregate) -> Self {
37 let mut volumes: HashMap<String, VolumeAggregateSer> = HashMap::new();
38 for volume in value.volumes {
39 volumes.insert(volume.volume.clone(), Into::into(volume.clone()));
40 }
41 MangaAggregatSer {
42 result: value.result,
43 volumes,
44 }
45 }
46}
47
48#[cfg(feature = "serialize")]
49#[derive(serde::Serialize, Clone)]
50#[cfg_attr(feature = "specta", derive(specta::Type))]
51pub struct MangaAggregatSer {
52 result: ResultType,
53 volumes: HashMap<String, VolumeAggregateSer>,
54}
55
56#[cfg(feature = "serialize")]
57#[derive(serde::Serialize, Clone)]
58#[cfg_attr(feature = "specta", derive(specta::Type))]
59pub struct VolumeAggregateSer {
60 pub volume: String,
62 pub count: u32,
64 pub chapters: HashMap<String, ChapterAggregate>,
66}
67
68#[cfg(feature = "serialize")]
69impl Serialize for MangaAggregate {
70 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
71 where
72 S: serde::Serializer,
73 {
74 let ser: MangaAggregatSer = Into::into(self.clone());
75 ser.serialize(serializer)
76 }
77}
78
79#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
80#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
81#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
82#[cfg_attr(feature = "specta", derive(specta::Type))]
83pub struct VolumeAggregate {
84 pub volume: String,
86 pub count: u32,
88 #[serde(with = "chapter_aggregate_array_or_map")]
90 pub chapters: Vec<ChapterAggregate>,
91}
92
93#[cfg(feature = "serialize")]
94#[allow(clippy::from_over_into)]
95impl From<VolumeAggregate> for VolumeAggregateSer {
96 fn from(value: VolumeAggregate) -> Self {
97 let mut chapters: HashMap<String, ChapterAggregate> = HashMap::new();
98 for chapter in value.chapters {
99 chapters.insert(chapter.chapter.clone(), chapter);
100 }
101 VolumeAggregateSer {
102 volume: value.volume,
103 count: value.count,
104 chapters,
105 }
106 }
107}
108
109#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
110#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
111#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
112#[cfg_attr(feature = "specta", derive(specta::Type))]
113pub struct ChapterAggregate {
114 pub chapter: String,
116 pub id: Uuid,
117 pub others: Vec<Uuid>,
119 pub count: u32,
121}