|
| 1 | +#[cfg(feature = "mangadex-api-resolver")] |
| 2 | +use mangadex_api::{v5::scanlation_group::post::CreateGroupBuilder, MangaDexClient}; |
| 3 | + |
| 4 | +#[cfg(feature = "mangadex-api-resolver")] |
| 5 | +use mangadex_api_schema::{v5::GroupData, Limited}; |
| 6 | +#[cfg(feature = "mangadex-api-resolver")] |
| 7 | +use mangadex_api_types::error::Result; |
| 8 | + |
| 9 | +use mangadex_api_types::MangaDexDuration; |
| 10 | +use serde::{Deserialize, Serialize}; |
| 11 | +use specta::Type; |
| 12 | +use url::Url; |
| 13 | + |
| 14 | +#[derive(Debug, Clone, Type, Serialize, Deserialize)] |
| 15 | +pub struct CreateScalantionGroupParam { |
| 16 | + pub name: String, |
| 17 | + /// Nullable. |
| 18 | + #[serde(default)] |
| 19 | + pub website: Option<String>, |
| 20 | + /// Nullable. |
| 21 | + #[serde(default)] |
| 22 | + pub irc_server: Option<String>, |
| 23 | + /// Nullable. |
| 24 | + #[serde(default)] |
| 25 | + pub irc_channel: Option<String>, |
| 26 | + /// Nullable. |
| 27 | + #[serde(default)] |
| 28 | + pub discord: Option<String>, |
| 29 | + /// Nullable. |
| 30 | + #[serde(default)] |
| 31 | + pub contact_email: Option<String>, |
| 32 | + /// Nullable. |
| 33 | + #[serde(default)] |
| 34 | + pub description: Option<String>, |
| 35 | + /// Nullable. |
| 36 | + #[serde(default)] |
| 37 | + pub twitter: Option<Url>, |
| 38 | + /// Regex: [^https:/\/www\.mangaupdates\.com\/(?:groups|publishers)\.html\?id=\d+](https://www.mangaupdates.com) |
| 39 | + /// |
| 40 | + /// Nullable. |
| 41 | + #[serde(default)] |
| 42 | + pub manga_updates: Option<Url>, |
| 43 | + #[serde(default)] |
| 44 | + pub inactive: Option<bool>, |
| 45 | + /// Nullable. |
| 46 | + #[serde(default)] |
| 47 | + pub publish_delay: Option<MangaDexDuration>, |
| 48 | +} |
| 49 | + |
| 50 | +#[cfg(feature = "mangadex-api-resolver")] |
| 51 | +impl From<CreateScalantionGroupParam> for CreateGroupBuilder { |
| 52 | + fn from(value: CreateScalantionGroupParam) -> Self { |
| 53 | + let mut builder = Self::default(); |
| 54 | + builder.name(value.name); |
| 55 | + if let Some(website) = value.website { |
| 56 | + builder.website(website); |
| 57 | + } |
| 58 | + if let Some(irc_server) = value.irc_server { |
| 59 | + builder.irc_server(irc_server); |
| 60 | + } |
| 61 | + if let Some(irc_channel) = value.irc_channel { |
| 62 | + builder.irc_channel(irc_channel); |
| 63 | + } |
| 64 | + if let Some(discord) = value.discord { |
| 65 | + builder.discord(discord); |
| 66 | + } |
| 67 | + if let Some(contact_email) = value.contact_email { |
| 68 | + builder.contact_email(contact_email); |
| 69 | + } |
| 70 | + if let Some(description) = value.description { |
| 71 | + builder.description(description); |
| 72 | + } |
| 73 | + if let Some(twitter) = value.twitter { |
| 74 | + builder.twitter(twitter); |
| 75 | + } |
| 76 | + if let Some(manga_updates) = value.manga_updates { |
| 77 | + builder.manga_updates(manga_updates); |
| 78 | + } |
| 79 | + if let Some(inactive) = value.inactive { |
| 80 | + builder.inactive(inactive); |
| 81 | + } |
| 82 | + if let Some(publish_delay) = value.publish_delay { |
| 83 | + builder.publish_delay(publish_delay); |
| 84 | + } |
| 85 | + builder |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +#[cfg(feature = "mangadex-api-resolver")] |
| 90 | +impl CreateScalantionGroupParam { |
| 91 | + pub async fn send(self, client: &MangaDexClient) -> Result<Limited<GroupData>> { |
| 92 | + <CreateGroupBuilder as From<Self>>::from(self) |
| 93 | + .http_client(client.get_http_client().clone()) |
| 94 | + .send() |
| 95 | + .await |
| 96 | + } |
| 97 | +} |
0 commit comments