feature/apps
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use std::fmt::Display; |
| 2 | |
| 3 | use chrono::{DateTime, Utc}; |
| 4 | use serde::{Deserialize, Serialize}; |
| 5 | use spinners::Spinner; |
| 6 | |
| 7 | mod ar_date_format { |
| 8 | use chrono::{DateTime, TimeZone, Utc}; |
| 9 | use serde::{self, Deserialize, Deserializer, Serializer}; |
| 10 | |
| 11 | const FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.f%#z"; |
| 12 | |
| 13 | // The signature of a serialize_with function must follow the pattern: |
| 14 | // |
| 15 | // fn serialize<S>(&T, S) -> Result<S::Ok, S::Error> |
| 16 | // where |
| 17 | // S: Serializer |
| 18 | // |
| 19 | // although it may also be generic over the input types T. |
| 20 | pub fn serialize<S>(date: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error> |
| 21 | where |
| 22 | S: Serializer, |
| 23 | { |
| 24 | let s = format!("{}", date.naive_utc()); |
| 25 | serializer.serialize_str(&s) |
| 26 | } |
| 27 | |
| 28 | // The signature of a deserialize_with function must follow the pattern: |
| 29 | // |
| 30 | // fn deserialize<'de, D>(D) -> Result<T, D::Error> |
| 31 | // where |
| 32 | // D: Deserializer<'de> |
| 33 | // |
| 34 | // although it may also be generic over the output types T. |
| 35 | pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error> |
| 36 | where |
| 37 | D: Deserializer<'de>, |
| 38 | { |
| 39 | let s = String::deserialize(deserializer)?; |
| 40 | Utc.datetime_from_str(&s, FORMAT) |
| 41 | .map_err(serde::de::Error::custom) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | pub struct CommandResult { |
| 46 | pub spinner: Spinner, |
| 47 | pub symbol: String, |
| 48 | pub msg: String, |
| 49 | } |
| 50 | |
| 51 | #[derive(Serialize, Deserialize, Debug)] |
| 52 | pub struct Oten { |
| 53 | pub id: String, |
| 54 | pub secret: Option<String>, |
| 55 | pub name: String, |
| 56 | #[serde(with = "ar_date_format")] |
| 57 | pub created_at: DateTime<Utc>, |
| 58 | #[serde(with = "ar_date_format")] |
| 59 | pub updated_at: DateTime<Utc>, |
| 60 | } |
| 61 | |
| 62 | #[derive(Serialize, Deserialize, Debug)] |
| 63 | pub struct Fun { |
| 64 | pub id: String, |
| 65 | pub secret: Option<String>, |
| 66 | pub name: String, |
| 67 | #[serde(with = "ar_date_format")] |
| 68 | pub created_at: DateTime<Utc>, |
| 69 | #[serde(with = "ar_date_format")] |
| 70 | pub updated_at: DateTime<Utc>, |
| 71 | } |
| 72 | |
| 73 | #[derive(Serialize, Deserialize, Debug)] |
| 74 | pub struct Pkt { |
| 75 | pub id: String, |
| 76 | pub secret: Option<String>, |
| 77 | pub name: String, |
| 78 | #[serde(with = "ar_date_format")] |
| 79 | pub created_at: DateTime<Utc>, |
| 80 | #[serde(with = "ar_date_format")] |
| 81 | pub updated_at: DateTime<Utc>, |
| 82 | } |
| 83 | |
| 84 | #[derive(Serialize, Deserialize, Debug)] |
| 85 | pub struct Rdb { |
| 86 | pub id: String, |
| 87 | pub secret: Option<String>, |
| 88 | pub name: String, |
| 89 | #[serde(with = "ar_date_format")] |
| 90 | pub created_at: DateTime<Utc>, |
| 91 | #[serde(with = "ar_date_format")] |
| 92 | pub updated_at: DateTime<Utc>, |
| 93 | } |
| 94 | |
| 95 | #[derive(Serialize, Deserialize, Debug)] |
| 96 | pub struct AppCreate { |
| 97 | pub name: String, |
| 98 | pub description: String, |
| 99 | } |
| 100 | |
| 101 | pub mod create_params { |
| 102 | use serde::{Deserialize, Serialize}; |
| 103 | |
| 104 | #[derive(Deserialize, Debug, Serialize)] |
| 105 | pub struct Oten { |
| 106 | pub oten_app: AppCreate, |
| 107 | } |
| 108 | |
| 109 | #[derive(Deserialize, Debug, Serialize)] |
| 110 | pub struct AppCreate { |
| 111 | pub name: String, |
| 112 | pub project_id: i32, |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | #[derive(Deserialize, Debug, Serialize)] |
| 117 | pub struct Config { |
| 118 | pub current_project: Option<Project>, |
| 119 | pub current_oten_app: Option<Oten>, |
| 120 | pub current_fun_app: Option<Fun>, |
| 121 | pub current_pkt_app: Option<Pkt>, |
| 122 | pub current_rdb_app: Option<Rdb>, |
| 123 | } |
| 124 | |
| 125 | #[derive(Deserialize, Debug, Serialize, Clone)] |
| 126 | pub struct Project { |
| 127 | pub id: i32, |
| 128 | pub name: String, |
| 129 | #[serde(with = "ar_date_format")] |
| 130 | pub created_at: DateTime<Utc>, |
| 131 | #[serde(with = "ar_date_format")] |
| 132 | pub updated_at: DateTime<Utc>, |
| 133 | } |
| 134 | |
| 135 | impl Display for Project { |
| 136 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 137 | let id = self.id.to_string(); |
| 138 | let name = self.name.to_string(); |
| 139 | let created_at = self.created_at.date_naive(); |
| 140 | let updated_at = self.updated_at.date_naive(); |
| 141 | write!( |
| 142 | f, |
| 143 | "{0: <5} | {1: <20} | {2: <30} | {3: <30}", |
| 144 | id, name, created_at, updated_at |
| 145 | ) |
| 146 | } |
| 147 | } |
| 148 | #[derive(Serialize, Debug)] |
| 149 | pub struct ProjectCreate { |
| 150 | pub name: String, |
| 151 | pub description: String, |
| 152 | } |