Skip to content

Commit 6f20c4e

Browse files
authored
Merge pull request tonymushah#111 from tonymushah/user-param-types
User param types
2 parents 46f4e8c + 36bc587 commit 6f20c4e

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed

mangadex-api-params-types/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ pub mod scanlation_group;
1818
pub mod settings;
1919
pub mod statistics;
2020
pub mod upload;
21+
pub mod user;
+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub mod begin_edit_session;
22
pub mod begin_session;
33
pub mod commit;
4+
pub mod delete_uploaded_image;
5+
pub mod delete_uploaded_images;
46
pub mod upload_image;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#[cfg(feature = "mangadex-api-resolver")]
2+
use mangadex_api::{
3+
v5::upload::upload_session_id::upload_session_file_id::delete::DeleteImageBuilder,
4+
MangaDexClient,
5+
};
6+
#[cfg(feature = "mangadex-api-resolver")]
7+
use mangadex_api_schema::Limited;
8+
#[cfg(feature = "mangadex-api-resolver")]
9+
use mangadex_api_types::error::Result;
10+
11+
use serde::{Deserialize, Serialize};
12+
use specta::Type;
13+
use uuid::Uuid;
14+
15+
#[derive(Debug, Clone, Type, Serialize, Deserialize)]
16+
pub struct DeleteImageParam {
17+
pub session_id: Uuid,
18+
pub session_file_id: Uuid,
19+
}
20+
21+
#[cfg(feature = "mangadex-api-resolver")]
22+
impl From<DeleteImageParam> for DeleteImageBuilder {
23+
fn from(value: DeleteImageParam) -> Self {
24+
let mut builder = Self::default();
25+
builder.session_id(value.session_id);
26+
builder.session_file_id(value.session_file_id);
27+
builder
28+
}
29+
}
30+
31+
#[cfg(feature = "mangadex-api-resolver")]
32+
impl DeleteImageParam {
33+
pub async fn send(self, client: &MangaDexClient) -> Result<Limited<()>> {
34+
let data = <DeleteImageBuilder as From<Self>>::from(self)
35+
.http_client(client.get_http_client().clone())
36+
.send()
37+
.await?;
38+
Ok(Limited {
39+
rate_limit: data.rate_limit,
40+
body: (),
41+
})
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#[cfg(feature = "mangadex-api-resolver")]
2+
use mangadex_api::{
3+
v5::upload::upload_session_id::batch::delete::DeleteImagesBuilder, MangaDexClient,
4+
};
5+
#[cfg(feature = "mangadex-api-resolver")]
6+
use mangadex_api_schema::Limited;
7+
#[cfg(feature = "mangadex-api-resolver")]
8+
use mangadex_api_types::error::Result;
9+
10+
use serde::{Deserialize, Serialize};
11+
use specta::Type;
12+
use uuid::Uuid;
13+
14+
#[derive(Debug, Clone, Type, Serialize, Deserialize)]
15+
pub struct DeleteImagesParam {
16+
pub session_id: Uuid,
17+
pub session_file_ids: Vec<Uuid>,
18+
}
19+
20+
#[cfg(feature = "mangadex-api-resolver")]
21+
impl From<DeleteImagesParam> for DeleteImagesBuilder {
22+
fn from(value: DeleteImagesParam) -> Self {
23+
let mut builder = Self::default();
24+
builder.session_id(value.session_id);
25+
builder.session_file_ids(value.session_file_ids);
26+
builder
27+
}
28+
}
29+
30+
#[cfg(feature = "mangadex-api-resolver")]
31+
impl DeleteImagesParam {
32+
pub async fn send(self, client: &MangaDexClient) -> Result<Limited<()>> {
33+
let res = <DeleteImagesBuilder as From<DeleteImagesParam>>::from(self)
34+
.http_client(client.get_http_client().clone())
35+
.send()
36+
.await?;
37+
Ok(Limited {
38+
rate_limit: res.rate_limit,
39+
body: (),
40+
})
41+
}
42+
}

mangadex-api-params-types/src/user.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod list;
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[cfg(feature = "mangadex-api-resolver")]
2+
use mangadex_api::{v5::user::get::ListUserBuilder, MangaDexClient};
3+
4+
use mangadex_api_types::UserSortOrder;
5+
use serde::{Deserialize, Serialize};
6+
use specta::Type;
7+
use uuid::Uuid;
8+
9+
#[derive(Debug, Clone, Type, Serialize, Deserialize, Default)]
10+
#[serde(default)]
11+
pub struct UserListParam {
12+
pub limit: Option<u32>,
13+
pub offset: Option<u32>,
14+
pub user_ids: Vec<Uuid>,
15+
pub username: Option<String>,
16+
pub order: Option<UserSortOrder>,
17+
}
18+
19+
#[cfg(feature = "mangadex-api-resolver")]
20+
impl From<UserListParam> for ListUserBuilder {
21+
fn from(value: UserListParam) -> Self {
22+
let mut builder = Self::default();
23+
if let Some(limit) = value.limit {
24+
builder.limit(limit);
25+
}
26+
if let Some(offset) = value.offset {
27+
builder.offset(offset);
28+
}
29+
builder.user_ids(value.user_ids);
30+
if let Some(username) = value.username {
31+
builder.username(username);
32+
}
33+
if let Some(order) = value.order {
34+
builder.order(order);
35+
}
36+
builder
37+
}
38+
}
39+
40+
#[cfg(feature = "mangadex-api-resolver")]
41+
impl UserListParam {
42+
pub async fn send(self, client: &MangaDexClient) -> mangadex_api_schema::v5::UserListResponse {
43+
<ListUserBuilder as From<Self>>::from(self)
44+
.http_client(client.get_http_client().clone())
45+
.send()
46+
.await
47+
}
48+
}

0 commit comments

Comments
 (0)