casdoor_rust_sdk/
pricing.rs1use serde::{Deserialize, Serialize};
16
17use crate::client::{get_owner, Client, Response};
18use crate::error::Result;
19use crate::serde_util::null_to_default;
20
21#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase", default)]
25pub struct Pricing {
26 pub owner: String,
27 pub name: String,
28 pub created_time: String,
29 pub display_name: String,
30 pub description: String,
31
32 #[serde(deserialize_with = "null_to_default")]
33 pub plans: Vec<String>,
34 pub is_enabled: bool,
35 pub trial_duration: i32,
36 pub application: String,
37}
38
39impl Client {
40 pub async fn get_pricings(&self) -> Result<Vec<Pricing>> {
42 self.get_list("get-pricings", &[("owner", &self.config.organization_name)])
43 .await
44 }
45
46 pub async fn get_pagination_pricings(
49 &self,
50 p: i32,
51 page_size: i32,
52 query: &[(&str, &str)],
53 ) -> Result<(Vec<Pricing>, i32)> {
54 self.get_pagination(
55 "get-pricings",
56 &self.config.organization_name,
57 p,
58 page_size,
59 query,
60 )
61 .await
62 }
63
64 pub async fn get_pricing(&self, name: &str) -> Result<Option<Pricing>> {
66 self.get_object("get-pricing", &[("id", &self.get_id(name))])
67 .await
68 }
69
70 pub async fn add_pricing(&self, pricing: &Pricing) -> Result<bool> {
72 Ok(self.modify_pricing("add-pricing", pricing, &[]).await?.1)
73 }
74
75 pub async fn update_pricing(&self, pricing: &Pricing) -> Result<bool> {
77 Ok(self.modify_pricing("update-pricing", pricing, &[]).await?.1)
78 }
79
80 pub async fn delete_pricing(&self, pricing: &Pricing) -> Result<bool> {
82 Ok(self.modify_pricing("delete-pricing", pricing, &[]).await?.1)
83 }
84
85 async fn modify_pricing(
86 &self,
87 action: &str,
88 pricing: &Pricing,
89 columns: &[&str],
90 ) -> Result<(Response, bool)> {
91 let mut pricing = pricing.clone();
92 pricing.owner = get_owner(&pricing.owner, &self.config.organization_name);
93
94 let id = format!("{}/{}", pricing.owner, pricing.name);
95 self.modify_object(action, &id, &pricing, columns).await
96 }
97}