chore: support into trait for subscription plan and recurring interval

This commit is contained in:
Zack Fu Zi Xiang 2024-07-09 13:23:15 +08:00
parent 8b5a803d44
commit 9c3529f0ca
No known key found for this signature in database
1 changed files with 23 additions and 2 deletions

View File

@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum RecurringInterval {
Month,
Year,
Month = 0,
Year = 1,
}
impl RecurringInterval {
@ -28,6 +28,15 @@ impl TryFrom<i16> for RecurringInterval {
}
}
impl Into<i16> for RecurringInterval {
fn into(self) -> i16 {
match self {
RecurringInterval::Month => 0,
RecurringInterval::Year => 1,
}
}
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
#[repr(i16)]
@ -55,6 +64,18 @@ impl TryFrom<i16> for SubscriptionPlan {
}
}
impl Into<i16> for SubscriptionPlan {
fn into(self) -> i16 {
match self {
SubscriptionPlan::Free => 0,
SubscriptionPlan::Pro => 1,
SubscriptionPlan::Team => 2,
SubscriptionPlan::AiMax => 3,
SubscriptionPlan::AiLocal => 4,
}
}
}
impl AsRef<str> for SubscriptionPlan {
fn as_ref(&self) -> &str {
match self {