chore: add try from for subscription plan

This commit is contained in:
Zack Fu Zi Xiang 2024-07-10 18:54:39 +08:00
parent 549e0ac9d7
commit e0e7950ae1
No known key found for this signature in database
1 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,21 @@ impl AsRef<str> for SubscriptionPlan {
}
}
impl TryFrom<&str> for SubscriptionPlan {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"free" => Ok(SubscriptionPlan::Free),
"pro" => Ok(SubscriptionPlan::Pro),
"team" => Ok(SubscriptionPlan::Team),
"ai_max" => Ok(SubscriptionPlan::AiMax),
"ai_local" => Ok(SubscriptionPlan::AiLocal),
_ => Err(format!("Invalid SubscriptionPlan value: {}", value)),
}
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SubscriptionStatus {