smbcloud_model/
app_auth.rs1use crate::ar_date_format;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use tsync::tsync;
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct AuthApp {
8 pub id: String,
9 pub secret: Option<String>,
10 pub name: String,
11 pub project_id: Option<String>,
12 pub support_email: Option<String>,
13 #[serde(with = "ar_date_format")]
14 pub created_at: DateTime<Utc>,
15 #[serde(with = "ar_date_format")]
16 pub updated_at: DateTime<Utc>,
17}
18
19#[derive(Serialize, Deserialize, Debug, Clone)]
20pub struct AuthAppCreate {
21 pub name: String,
22 pub project_id: String,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub support_email: Option<String>,
25}
26
27#[derive(Serialize, Deserialize, Debug, Clone, Default)]
28pub struct AuthAppUpdate {
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub name: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub support_email: Option<String>,
33}
34
35impl AuthAppUpdate {
36 pub fn is_empty(&self) -> bool {
37 self.name.is_none() && self.support_email.is_none()
38 }
39}
40
41#[derive(Serialize, Deserialize, Debug, Clone)]
49#[tsync]
50pub struct AuthAppClient {
51 pub id: i64,
52 pub client_id: String,
53 pub name: String,
54 pub redirect_uris: String,
55 pub confidential: bool,
56 pub auth_app_id: String,
57 #[serde(with = "ar_date_format")]
58 pub created_at: DateTime<Utc>,
59 #[serde(with = "ar_date_format")]
60 pub updated_at: DateTime<Utc>,
61}
62
63#[derive(Serialize, Deserialize, Debug, Clone)]
67#[tsync]
68pub struct AuthAppClientCreate {
69 pub name: String,
70 pub redirect_uris: String,
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76 use serde_json::json;
77 #[test]
78 fn test_auth_app_create() {
79 let auth_app_create = AuthAppCreate {
80 name: "test".to_owned(),
81 project_id: "1".to_owned(),
82 support_email: None,
83 };
84 let json = json!({
85 "name": "test",
86 "project_id": "1",
87 });
88 assert_eq!(serde_json::to_value(auth_app_create).unwrap(), json);
89 }
90}