mangadex_api/v5/manga/status/
get.rs

1//! Builder for the manga reading status endpoint.
2//!
3//! <https://api.mangadex.org/docs/swagger.html#/Manga/get-manga-status>
4//!
5//! # Examples
6//!
7//! ```rust
8//! use mangadex_api_types::ReadingStatus;
9//! use mangadex_api::v5::MangaDexClient;
10//!
11//! # async fn run() -> anyhow::Result<()> {
12//! let client = MangaDexClient::default();
13//!
14//! let res = client
15//!     .manga()
16//!     .status()
17//!     .get()
18//!     .status(ReadingStatus::Reading)
19//!     .send()
20//!     .await?;
21//!
22//! println!("statuses: {:?}", res);
23//! # Ok(())
24//! # }
25//! ```
26
27use derive_builder::Builder;
28use serde::Serialize;
29
30use crate::HttpClientRef;
31use mangadex_api_schema::v5::MangaReadingStatusesResponse;
32use mangadex_api_types::ReadingStatus;
33
34#[cfg_attr(
35    feature = "deserializable-endpoint",
36    derive(serde::Deserialize, getset::Getters, getset::Setters)
37)]
38#[derive(Debug, Serialize, Clone, Builder, Default)]
39#[serde(rename_all = "camelCase")]
40#[builder(
41    setter(into, strip_option),
42    default,
43    build_fn(error = "mangadex_api_types::error::BuilderError")
44)]
45#[cfg_attr(
46    feature = "custom_list_v2",
47    deprecated(
48        since = "3.0.0-alpha.1",
49        note = "After the introduction of the Subscription system, this endpoint will be removed in 3.0.0"
50    )
51)]
52pub struct MangaReadingStatuses {
53    /// This should never be set manually as this is only for internal use.
54    #[doc(hidden)]
55    #[serde(skip)]
56    #[builder(pattern = "immutable")]
57    #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
58    pub http_client: HttpClientRef,
59
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub status: Option<ReadingStatus>,
62}
63
64endpoint! {
65    GET "/manga/status",
66    #[query auth] MangaReadingStatuses,
67    #[flatten_result] MangaReadingStatusesResponse,
68    MangaReadingStatusesBuilder
69}
70
71#[cfg(test)]
72mod tests {
73    use serde_json::json;
74    use url::Url;
75    use wiremock::matchers::{header, method, path};
76    use wiremock::{Mock, MockServer, ResponseTemplate};
77
78    use crate::v5::AuthTokens;
79    use crate::{HttpClient, MangaDexClient};
80
81    #[tokio::test]
82    async fn manga_reading_status_fires_a_request_to_base_url() -> anyhow::Result<()> {
83        let mock_server = MockServer::start().await;
84        let http_client = HttpClient::builder()
85            .base_url(Url::parse(&mock_server.uri())?)
86            .auth_tokens(AuthTokens {
87                session: "sessiontoken".to_string(),
88                refresh: "refreshtoken".to_string(),
89            })
90            .build()?;
91        let mangadex_client = MangaDexClient::new_with_http_client(http_client);
92
93        let response_body = json!({
94            "result": "ok",
95            "statuses": {
96                "b019ea5d-5fe6-44d4-abbc-f546f210884d": "reading",
97                "2394a5c7-1d2e-461f-acde-18726b9e37d6": "dropped"
98            }
99        });
100
101        Mock::given(method("GET"))
102            .and(path(r"/manga/status"))
103            .and(header("Authorization", "Bearer sessiontoken"))
104            .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
105            .expect(1)
106            .mount(&mock_server)
107            .await;
108
109        let _ = mangadex_client.manga().status().get().send().await?;
110
111        Ok(())
112    }
113}