From 9c3529f0cabf85312456a93b0a61d92bddd6b99f Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Tue, 9 Jul 2024 13:23:15 +0800 Subject: [PATCH] chore: support into trait for subscription plan and recurring interval --- libs/shared-entity/src/dto/billing_dto.rs | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/shared-entity/src/dto/billing_dto.rs b/libs/shared-entity/src/dto/billing_dto.rs index 8d25cc50..fb71f465 100644 --- a/libs/shared-entity/src/dto/billing_dto.rs +++ b/libs/shared-entity/src/dto/billing_dto.rs @@ -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 for RecurringInterval { } } +impl Into 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 for SubscriptionPlan { } } +impl Into 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 for SubscriptionPlan { fn as_ref(&self) -> &str { match self {