mango_api/requests/
manga.rs

1//! Utilities for manga specific server part of the application.
2//!
3//! The meaning of most of the confusing structs here can be found at <https://api.mangadex.org/docs/3-enumerations/#manga-links-data>
4//!
5//! All queries encountered here can be constructed with the builder syntax from the [bon] crate
6
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10use std::collections::HashMap;
11
12use super::query_utils::{
13    ContentRating, LocalizedString, PublicationDemographic, Query, Relationship, SortingOptions,
14};
15use super::tag::{Tag, TagsMode};
16use super::{Entity, EntityType, Locale};
17
18use bon::Builder;
19
20/// Used for serialization/deserialization
21#[derive(Serialize, Deserialize, Debug, Clone)]
22#[serde(rename_all = "snake_case")]
23pub enum MangaStatus {
24    Completed,
25    Ongoing,
26    Cancelled,
27    Hiatus,
28}
29
30/// Used for serialization/deserialization
31/// If you intend to understand this mess, please refer to <https://api.mangadex.org/docs/3-enumerations/#manga-links-data>
32#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, std::hash::Hash, Clone)]
33#[serde(rename_all = "camelCase")]
34pub enum MangaLinkSource {
35    Al,
36    Ap,
37    Bw,
38    Mu,
39    Nu,
40    Kt,
41    Amz,
42    Ebj,
43    Mal,
44    Cdj,
45    Raw,
46    Engtl,
47}
48
49pub type MangaLinks = HashMap<MangaLinkSource, String>;
50
51/// Used for serialization/deserialization
52#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
53#[serde(rename_all = "snake_case")]
54pub enum MangaState {
55    Draft,
56    Submitted,
57    Published,
58    Rejected,
59}
60
61/// Used for serialization/deserialization
62#[derive(Serialize, Deserialize, Debug, Clone)]
63#[serde(rename_all = "camelCase")]
64pub struct MangaAttributes {
65    pub title: LocalizedString,
66    pub alt_titles: Vec<LocalizedString>,
67    pub description: LocalizedString,
68    pub is_locked: bool,
69    pub links: MangaLinks,
70    pub original_language: Locale,
71    pub last_volume: Option<String>,
72    pub last_chapter: Option<String>,
73    pub publication_demographic: Option<PublicationDemographic>,
74    pub status: MangaStatus,
75    pub year: Option<isize>,
76    pub content_rating: ContentRating,
77    pub chapter_numbers_reset_on_new_volume: bool,
78    pub available_translated_languages: Vec<Locale>,
79    pub latest_uploaded_chapter: String,
80    pub tags: Vec<Tag>,
81    pub state: MangaState,
82    pub version: usize,
83    pub created_at: String,
84    pub updated_at: String,
85}
86
87/// Used for serialization/deserialization.
88/// Main structure used for representing the response containg manga info
89#[derive(Serialize, Deserialize, Debug, Clone)]
90pub struct Manga {
91    pub id: String,
92    #[serde(rename(deserialize = "type"))]
93    pub entity_type: EntityType,
94    pub attributes: MangaAttributes,
95    pub relationships: Vec<Relationship>,
96}
97
98impl Entity for Manga {}
99
100/// Query that is used for parameterization manga searches
101#[derive(Serialize, Deserialize, Debug, Clone, Default, Builder)]
102#[builder(on(String, into))]
103#[serde(rename_all = "camelCase")]
104pub struct MangaQuery {
105    pub limit: Option<usize>,
106    pub offset: Option<usize>,
107    pub title: Option<String>,
108    pub author_or_artist: Option<String>,
109    pub authors: Option<Vec<String>>,
110    pub artists: Option<Vec<String>>,
111    pub year: Option<usize>,
112    pub included_tags: Option<Vec<Tag>>,
113    pub included_tags_mode: Option<TagsMode>,
114    pub excluded_tags: Option<Vec<Tag>>,
115    pub excluded_tags_mode: Option<TagsMode>,
116    pub status: Option<Vec<MangaStatus>>,
117    pub original_language: Option<Vec<Locale>>,
118    pub excluded_original_language: Option<Vec<Locale>>,
119    pub available_translated_language: Option<Vec<Locale>>,
120    pub publication_demographic: Option<Vec<PublicationDemographic>>,
121    pub ids: Option<Vec<String>>,
122    pub content_rating: Option<Vec<ContentRating>>,
123    pub created_at_since: Option<String>,
124    pub updated_at_since: Option<String>,
125    pub order: Option<SortingOptions>,
126    pub includes: Option<Value>,
127    pub has_available_chapters: Option<String>,
128    pub group: Option<String>,
129}
130
131impl Query for MangaQuery {}
132
133/// Query used for parameterization of manga feed queries
134#[derive(Serialize, Deserialize, Debug, Clone, Default, Builder)]
135#[builder(on(String, into))]
136#[serde(rename_all = "camelCase")]
137pub struct MangaFeedQuery {
138    pub limit: Option<usize>,
139    pub offset: Option<usize>,
140    pub translated_language: Option<Vec<Locale>>,
141    pub original_language: Option<Vec<Locale>>,
142    pub excluded_original_language: Option<Vec<Locale>>,
143    pub content_rating: Option<Vec<ContentRating>>,
144    pub excluded_groups: Option<Vec<String>>,
145    pub include_future_updates: Option<String>,
146    pub created_at_since: Option<String>,
147    pub updated_at_since: Option<String>,
148    pub publish_at_since: Option<String>,
149    pub order: Option<SortingOptions>,
150    pub includes: Option<Value>,
151    pub include_empty_pages: Option<usize>,
152    pub include_future_publish_at: Option<usize>,
153    pub include_external_url: Option<usize>,
154}
155
156impl Query for MangaFeedQuery {}
157
158/// This struct is used to represent possible relation of [Manga] that can be encountered in
159/// its [Relationship]
160#[derive(Serialize, Deserialize, Clone, Debug)]
161#[serde(rename_all = "snake_case")]
162pub enum MangaRelation {
163    Monochrome,
164    MainStory,
165    AdaptedFrom,
166    BasedOn,
167    Prequel,
168    SideStory,
169    Doujinshi,
170    SameFranchise,
171    SharedUniverse,
172    Sequel,
173    SpinOff,
174    AlternateStory,
175    AlternateVersion,
176    Preserialization,
177    Colored,
178    Serialization,
179}