From 1d391e68e59749470ceb8a17dfb82588415e5ac1 Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:14:07 -0700 Subject: [PATCH] Better ser/deser for payouts vals (#474) --- src/models/users.rs | 17 ++++++++++++----- src/queue/payouts.rs | 5 ++--- src/routes/users.rs | 6 +++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/models/users.rs b/src/models/users.rs index 4d5246c7..1aa338ae 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -58,7 +58,7 @@ pub struct UserPayoutData { } #[derive(Serialize, Deserialize, Clone, Eq, PartialEq)] -#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +#[serde(rename_all = "snake_case")] pub enum RecipientType { Email, Phone, @@ -90,10 +90,10 @@ impl RecipientType { } #[derive(Serialize, Deserialize, Clone, Eq, PartialEq)] -#[serde(rename_all = "PascalCase")] +#[serde(rename_all = "snake_case")] pub enum RecipientWallet { Venmo, - PayPal, + Paypal, } impl std::fmt::Display for RecipientWallet { @@ -106,16 +106,23 @@ impl RecipientWallet { pub fn from_string(string: &str) -> RecipientWallet { match string { "venmo" => RecipientWallet::Venmo, - _ => RecipientWallet::PayPal, + _ => RecipientWallet::Paypal, } } pub fn as_str(&self) -> &'static str { match self { - RecipientWallet::PayPal => "paypal", + RecipientWallet::Paypal => "paypal", RecipientWallet::Venmo => "venmo", } } + + pub fn as_str_api(&self) -> &'static str { + match self { + RecipientWallet::Paypal => "PayPal", + RecipientWallet::Venmo => "Venmo", + } + } } use crate::database::models::user_item::User as DBUser; diff --git a/src/queue/payouts.rs b/src/queue/payouts.rs index c0c694d6..af0b887a 100644 --- a/src/queue/payouts.rs +++ b/src/queue/payouts.rs @@ -1,4 +1,3 @@ -use crate::models::users::{RecipientType, RecipientWallet}; use crate::routes::ApiError; use chrono::{DateTime, Duration, Utc}; use serde::{Deserialize, Serialize}; @@ -22,8 +21,8 @@ pub struct PayoutItem { pub amount: PayoutAmount, pub receiver: String, pub note: String, - pub recipient_type: RecipientType, - pub recipient_wallet: RecipientWallet, + pub recipient_type: String, + pub recipient_wallet: String, pub sender_item_id: String, } diff --git a/src/routes/users.rs b/src/routes/users.rs index 2b618295..22ac063e 100644 --- a/src/routes/users.rs +++ b/src/routes/users.rs @@ -316,7 +316,7 @@ pub async fn user_edit( if let Some(payout_data) = &new_user.payout_data { if payout_data.payout_wallet_type == RecipientType::UserHandle - && payout_data.payout_wallet == RecipientWallet::PayPal + && payout_data.payout_wallet == RecipientWallet::Paypal { return Err(ApiError::InvalidInput( "You cannot use a paypal wallet with a user handle!" @@ -741,8 +741,8 @@ pub async fn user_payouts_request( }, receiver: payout_address, note: "Payment from Modrinth creator monetization program".to_string(), - recipient_type: payout_wallet_type, - recipient_wallet: payout_wallet, + recipient_type: payout_wallet_type.to_string().to_uppercase(), + recipient_wallet: payout_wallet.as_str_api().to_string(), sender_item_id: format!("{}-{}", UserId::from(id), Utc::now().timestamp()), }) .await?;