mangadex_api/v5/user/list/
get.rs1use derive_builder::Builder;
43use serde::Serialize;
44
45use crate::HttpClientRef;
46use mangadex_api_schema::v5::CustomListListResponse;
47
48#[cfg_attr(
49 feature = "deserializable-endpoint",
50 derive(serde::Deserialize, getset::Getters, getset::Setters)
51)]
52#[derive(Debug, Serialize, Clone, Builder, Default)]
53#[serde(rename_all = "camelCase")]
54#[builder(
55 setter(into, strip_option),
56 default,
57 build_fn(error = "mangadex_api_types::error::BuilderError")
58)]
59pub struct MyCustomLists {
60 #[doc(hidden)]
62 #[serde(skip)]
63 #[builder(pattern = "immutable")]
64 #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
65 pub http_client: HttpClientRef,
66
67 #[serde(skip_serializing_if = "Option::is_none")]
68 pub limit: Option<u32>,
69 #[serde(skip_serializing_if = "Option::is_none")]
70 pub offset: Option<u32>,
71}
72
73endpoint! {
74 GET "/user/list",
75 #[query auth] MyCustomLists,
76 #[flatten_result] CustomListListResponse,
77 MyCustomListsBuilder
78}
79
80#[cfg(test)]
81mod tests {
82 use fake::faker::name::en::Name;
83 use fake::Fake;
84 use serde_json::json;
85 use url::Url;
86 use uuid::Uuid;
87 use wiremock::matchers::{header, method, path};
88 use wiremock::{Mock, MockServer, ResponseTemplate};
89
90 use crate::v5::AuthTokens;
91 use crate::{HttpClient, MangaDexClient};
92
93 #[tokio::test]
94 async fn get_my_custom_lists_fires_a_request_to_base_url() -> anyhow::Result<()> {
95 let mock_server = MockServer::start().await;
96 let http_client = HttpClient::builder()
97 .base_url(Url::parse(&mock_server.uri())?)
98 .auth_tokens(AuthTokens {
99 session: "sessiontoken".to_string(),
100 refresh: "refreshtoken".to_string(),
101 })
102 .build()?;
103 let mangadex_client = MangaDexClient::new_with_http_client(http_client);
104
105 let list_id = Uuid::new_v4();
106 let list_name: String = Name().fake();
107 let response_body = json!({
108 "result": "ok",
109 "response": "collection",
110 "data": [
111 {
112 "id": list_id,
113 "type": "custom_list",
114 "attributes": {
115 "name": list_name,
116 "visibility": "private",
117 "version": 1
118 },
119 "relationships": []
120 }
121 ],
122 "limit": 1,
123 "offset": 0,
124 "total": 1
125 });
126
127 Mock::given(method("GET"))
128 .and(path(r"/user/list"))
129 .and(header("Authorization", "Bearer sessiontoken"))
130 .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
131 .expect(1)
132 .mount(&mock_server)
133 .await;
134
135 let _ = mangadex_client
136 .user()
137 .list()
138 .get()
139 .limit(1_u32)
140 .send()
141 .await?;
142
143 Ok(())
144 }
145}