From 669c774327476a6ec50e28fc92f233d659566d27 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 2 Jul 2024 17:20:50 +0300 Subject: [PATCH] fixes --- src/api_params.rs | 18 +++++------ src/api_traits/async_telegram_api.rs | 14 ++++---- src/api_traits/telegram_api.rs | 14 ++++---- src/objects.rs | 48 +++++++++++++++++----------- 4 files changed, 52 insertions(+), 42 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index eb75bdb..2db49c2 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -1719,15 +1719,6 @@ pub struct UnpinAllForumTopicMessagesParams { pub message_thread_id: i32, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] -pub struct GetStarTransactionsParams { - #[builder(setter(into))] - offset: i32, - - #[builder(setter(into))] - limit: i32, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct EditGeneralForumTopicParams { #[builder(setter(into))] @@ -2481,6 +2472,15 @@ pub struct AnswerPreCheckoutQueryParams { pub error_message: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] +pub struct GetStarTransactionsParams { + #[builder(setter(into))] + offset: u32, + + #[builder(setter(into))] + limit: u32, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct RefundStarPaymentParams { pub user_id: u64, diff --git a/src/api_traits/async_telegram_api.rs b/src/api_traits/async_telegram_api.rs index 7ae18c3..ce956d6 100644 --- a/src/api_traits/async_telegram_api.rs +++ b/src/api_traits/async_telegram_api.rs @@ -1281,6 +1281,13 @@ pub trait AsyncTelegramApi { self.request("answerPreCheckoutQuery", Some(params)).await } + async fn get_star_transactions( + &self, + params: GetStarTransactionsParams, + ) -> Result, Self::Error> { + self.request("getStarTransactions", Some(params)).await + } + async fn refund_star_payment( &self, params: &RefundStarPaymentParams, @@ -1354,13 +1361,6 @@ pub trait AsyncTelegramApi { .await } - async fn get_star_transactions( - &self, - params: GetStarTransactionsParams, - ) -> Result, Self::Error> { - self.request("getStarTransactions", Some(params)).await - } - async fn request_without_body( &self, method: &str, diff --git a/src/api_traits/telegram_api.rs b/src/api_traits/telegram_api.rs index 758198a..a908643 100644 --- a/src/api_traits/telegram_api.rs +++ b/src/api_traits/telegram_api.rs @@ -1224,6 +1224,13 @@ pub trait TelegramApi { self.request("answerPreCheckoutQuery", Some(params)) } + fn get_star_transactions( + &self, + params: GetStarTransactionsParams, + ) -> Result, Self::Error> { + self.request("getStarTransactions", Some(params)) + } + fn refund_star_payment( &self, params: &RefundStarPaymentParams, @@ -1291,13 +1298,6 @@ pub trait TelegramApi { self.request("unpinAllGeneralForumTopicMessages", Some(params)) } - fn get_star_transactions( - &self, - params: GetStarTransactionsParams, - ) -> Result, Self::Error> { - self.request("getStarTransactions", Some(params)) - } - fn request_without_body( &self, method: &str, diff --git a/src/objects.rs b/src/objects.rs index 77ac695..5081c27 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -4096,59 +4096,69 @@ pub struct InaccessibleMessage { pub date: u64, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(tag = "type", rename_all = "snake_case")] pub enum RevenueWithdrawalState { - RevenueWithdrawalStatePending(RevenueWithdrawalStatePending), - RevenueWithdrawalStateSucceeded(RevenueWithdrawalStateSucceeded), - RevenueWithdrawalStateFailed(RevenueWithdrawalStateFailed), + Pending(RevenueWithdrawalStatePending), + Succeeded(RevenueWithdrawalStateSucceeded), + Failed(RevenueWithdrawalStateFailed), } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "pending", rename_all = "snake_case")] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)] pub struct RevenueWithdrawalStatePending {} -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "failed", rename_all = "snake_case")] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)] pub struct RevenueWithdrawalStateFailed {} -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "succeeded", rename_all = "snake_case")] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)] pub struct RevenueWithdrawalStateSucceeded { pub date: u64, + + #[builder(setter(into))] pub url: String, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "snake_case")] pub enum TransactionPartner { - TransactionPartnerFragment(TransactionPartnerFragment), - TransactionPartnerUser(TransactionPartnerUser), - TransactionPartnerOther(TransactionPartnerOther), + Fragment(TransactionPartnerFragment), + User(TransactionPartnerUser), + TelegramAds(TransactionPartnerTelegramAds), + Other(TransactionPartnerOther), } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "fragment", rename_all = "snake_case")] pub struct TransactionPartnerFragment { pub withdrawal_state: RevenueWithdrawalState, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "user", rename_all = "snake_case")] pub struct TransactionPartnerUser { pub user: User, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -#[serde(tag = "other", rename_all = "snake_case")] +pub struct TransactionPartnerTelegramAds {} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] pub struct TransactionPartnerOther {} #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] pub struct StarTransaction { #[builder(setter(into))] pub id: String, - pub amount: i32, + + pub amount: u32, + pub date: u64, - pub source: TransactionPartner, - pub receiver: TransactionPartner, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub source: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub receiver: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]