mangadex_api/v5/manga/id/list/list_id/
post.rs1use derive_builder::Builder;
47use serde::Serialize;
48use uuid::Uuid;
49
50use crate::HttpClientRef;
51use mangadex_api_schema::NoData;
52use mangadex_api_types::error::Result;
53
54#[cfg_attr(
55 feature = "deserializable-endpoint",
56 derive(serde::Deserialize, getset::Getters, getset::Setters)
57)]
58#[derive(Debug, Serialize, Clone, Builder)]
59#[serde(rename_all = "camelCase")]
60#[builder(
61 setter(into, strip_option),
62 build_fn(error = "mangadex_api_types::error::BuilderError")
63)]
64pub struct AddMangaToCustomList {
65 #[doc(hidden)]
67 #[serde(skip)]
68 #[builder(pattern = "immutable")]
69 #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
70 pub http_client: HttpClientRef,
71
72 #[serde(skip_serializing)]
73 pub manga_id: Uuid,
74 #[serde(skip_serializing)]
75 pub list_id: Uuid,
76}
77
78endpoint! {
79 POST ("/manga/{}/list/{}", manga_id, list_id),
80 #[no_data auth] AddMangaToCustomList,
81 #[discard_result] Result<NoData>,
82 AddMangaToCustomListBuilder
83}
84
85#[cfg(test)]
86mod tests {
87 use serde_json::json;
88 use url::Url;
89 use uuid::Uuid;
90 use wiremock::matchers::{header, method, path_regex};
91 use wiremock::{Mock, MockServer, ResponseTemplate};
92
93 use crate::v5::AuthTokens;
94 use crate::{HttpClient, MangaDexClient};
95
96 #[tokio::test]
97 async fn add_manga_to_custom_list_fires_a_request_to_base_url() -> anyhow::Result<()> {
98 let mock_server = MockServer::start().await;
99 let http_client = HttpClient::builder()
100 .base_url(Url::parse(&mock_server.uri())?)
101 .auth_tokens(AuthTokens {
102 session: "sessiontoken".to_string(),
103 refresh: "refreshtoken".to_string(),
104 })
105 .build()?;
106 let mangadex_client = MangaDexClient::new_with_http_client(http_client);
107
108 let manga_id = Uuid::new_v4();
109 let list_id = Uuid::new_v4();
110 let response_body = json!({
111 "result": "ok",
112 });
113
114 Mock::given(method("POST"))
115 .and(path_regex(r"/manga/[0-9a-fA-F-]+/list/[0-9a-fA-F-]+"))
116 .and(header("Authorization", "Bearer sessiontoken"))
117 .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
118 .expect(1)
119 .mount(&mock_server)
120 .await;
121
122 mangadex_client
123 .manga()
124 .id(manga_id)
125 .list()
126 .list_id(list_id)
127 .post()
128 .send()
129 .await?;
130
131 Ok(())
132 }
133}