|
| 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